I'm asking this question more out of curiosity. I was able to achieve my desired results using the filter() function but I'm interested in the explanation for the scenario below.
I wanted to use filter() to filter out values with multiple conditions using the != operator. I first tried using OR "|" but it wasn't correctly filtering out the values. It instead returned all the data back seemingly unfiltered. However, it worked when I used "&" instead (see below).
Ex.
data %>%
filter(SampleTypeName != "Grab" &
SampleTypeName != "Composite" &
SampleTypeName != "Integrated" &
SampleTypeName != "Not Applicable")
When I wanted to basically do the opposite, I filtered for values equal to the same set of strings above. I intuitively thought using "&" was also the solution. It instead returned all the data back seemingly unfiltered as well. Turns out, to achieve my desired results, I had to use "|" instead.
Ex.
data %>%
filter(SampleTypeName == "Grab" |
SampleTypeName == "Composite" |
SampleTypeName == "Integrated" |
SampleTypeName == "Not Applicable")
Why is this the case? I would appreciate both a semi-in-depth explanation and an explanation like I'm five :)
Thanks