Skip to content

Instantly share code, notes, and snippets.

@benmwhite
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save benmwhite/87c50d98c886dfb846e0 to your computer and use it in GitHub Desktop.

Select an option

Save benmwhite/87c50d98c886dfb846e0 to your computer and use it in GitHub Desktop.
R snippet for filtering data frames by vectors of values with dplyr's filter() function
#install.packages("dplyr")
library(dplyr)
#using built-in iris data set
str(iris)
#vector of values we want
vec <- c("versicolor", "virginica")
#using filter()
iris_subset <- filter(iris, Species %in% vec)
str(iris_subset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment