Using a pipe to sequentially filter data - receiving error

October 25, 2018 @ppines Patricia

@ppines wrote:

For some reason the equal sign in the last filter item is causing an error. I would appreciate some guidance as to why I can't use NIRData$ScanID =-1 for the variable ScanID equal to -1. See reprex below.

# Libraries

# Thresholds
Thresh.Brix.min <- 15
Thresh.Brix.max <- 30

Thresh.Pol.min <- 50
Thresh.Pol.max <- 105

Thresh.Fibre.min <- 4
Thresh.Fibre.max <- 25

Thresh.Ash.min <- 0
Thresh.Ash.max <- 8

# Import the NIRS data (NIRPred.csv), a CSV file with variable names in the first row, comma (“,”) as field separator character, and dot (“.”) as decimal point character
NIRData<- read.table("NIRPred.csv", header=TRUE, sep = ",", dec= ".")

# Display summary 

# Assign the DateTime variable to the POSIXct data type
NIRData$DateTime <- as.POSIXct(NIRData$DateTime, format = "%Y-%m-%d %H:%M:%S")

# Use transform() with the floor() function applied to ScanID to create a new variable called LabID in the NIRData table.
NIRData <- transform(NIRData, LABID = floor(NIRData$ScanID))

# Use a PIPE to sequentially filter the NIR data by filtering out any (a) GH values greater than 3.5, (b) NH values greater than 2, (c) any out-of-range values for Pol, Brix, Fibre and Ash and (d) any sample that has a ScanID equal to -1. Save the filtered data to a new data table called NIRData_Filtered. 
NIRData_Filtered <- NIRData_Filtered %>% filter (GH>3.5 & NH>2 & 
                                                   Thresh.Pol.min & Thresh.Pol.max &
                                                   Thresh.Brix.min & Thresh.Brix.max &
                                                   Thresh.Fibre.min & Thresh.Fibre.max &
                                                   Thresh.Ash.min & Thresh.Ash.max &
                                                   NIRData$ScanID =-1)
#> Error: <text>:43:67: unexpected '='
#> 42:                                                    Thresh.Ash.min & Thresh.Ash.max &
#> 43:                                                    NIRData$ScanID =
#>                                                                       ^

Posts: 4

Participants: 2

Read full topic

Previous Article
R Shiny reactive selectize highlight input in a plotly plot
R Shiny reactive selectize highlight input in a plotly plot

@arou wrote: Hi to all of you, I would like to have some help with a problem I h...

Next Article
[Video] Reproducible Examples and the `reprex` package
[Video] Reproducible Examples and the `reprex` package

@jennybryan wrote: Reproducible Examples and the reprex package Intro Basic usa...