1.8 Selecting observations

The dplyr::filter function allows you to limit your dataset to observations (rows) meeting a specific criteria. Multiple criteria can be combined with the & (AND) and | (OR) symbols.

library(dplyr)
data("starwars")

# select females
newdata <- filter(starwars, 
                  gender == "feminine")

# select females that are from Alderaan
newdata <- filter(starwars, 
                  gender == "feminine" & 
                  homeworld == "Alderaan")