1

How to filter rows that have value x in column j and value y in column j+1

so in the mtcars example lets say i want to filter out the rows where am =1 and gear = 5. The code below does not do the trick:

mtcars %>% filter(am != 1 & gear != 5)

Thanks

Jelle

Jelle Jansen
  • 448
  • 4
  • 16
  • Perhaps you have loaded another package that masks `filter`. Try `mtcars %>% dplyr::filter(am != 1, gear != 5)` – akrun Mar 22 '19 at 17:21
  • You can make a table with the combos you want to drop and anti join, see `?anti_join`. Also, in this case, there's `!(am==1 & gear==5)` -- which is not equivalent to the condition written in OP. – Frank Mar 22 '19 at 17:28
  • @akrun, this is not the case, your code also does not work since it filters out all am!=1 and not when both are true (am!=1 & gear != 5) – Jelle Jansen Mar 27 '19 at 09:08
  • A nice solution is maybe to paste the two columns together in a new column and filter this new column – Jelle Jansen Mar 27 '19 at 09:11

0 Answers0