Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 347
userfriendly Avatar asked Mar 21 '16 15:03

userfriendly


1 Answers

Try

df %>%
    filter(x <=4| y>=5)
like image 155
akrun Avatar answered Oct 05 '22 04:10

akrun