userfriendly
userfriendly

Reputation: 372

OR operator in filter()?

I want to use the filter() function to find the types that have an x value less than or equal to 4, OR a y value greater than 5. I think this might be a simple fix I just can't find much info on ?filter(). I almost have it I think:

x = c(1, 2, 3, 4, 5, 6)
y = c(3, 6, 1, 9, 1, 1)
type = c("cars", "bikes", "trains")

df = data.frame(x, y, type)

df2 = df %>% 
      filter(x<=4)

Upvotes: 19

Views: 78650

Answers (1)

akrun
akrun

Reputation: 887571

Try

df %>%
    filter(x <=4| y>=5)

Upvotes: 29

Related Questions