Is there a way to filter out multiple values at once using dplyr in R?

Viewed 75

I know you can filter for values you want to keep using %in% but what if I wanted to remove a few values at once and keep the rest?

For example, I have a bunch of rows with transects numbers I want to keep but I want to remove all rows with transects 137, 22, and 141.

1 Answers

Example with iris data, removing some values of Sepal.Length:

library(tidyverse)
remove_values = c(5.1, 4.9, 4.7)
iris %>% 
  filter(!(Sepal.Length %in% remove_values))
Related