Reputation: 2251
I am not sure what I am doing wrong. I have a data frame than contains more than one study. I want to filter STUDY number 7, 9, 120. I am using filter
in the dplyr
package like this:
df <- filter(data, STUDY==7, STUDY==9, STUDY==100)
This gives me a ZERO observations data frame. When I filter only one STUDY, it works. What is the right way to write it in order to filter a combination of studies?
Upvotes: 2
Views: 190
Reputation: 887851
Try
library(dplyr)
data %>%
filter(STUDY %in% c(7,9, 100))
Or
data %>%
filter(STUDY==7|STUDY==9|STUDY==100)
set.seed(24)
data <- data.frame(STUDY=sample(c(0,5,7,9,100,150,200),
25, replace=TRUE), Val=rnorm(25))
Upvotes: 7