Multiple filter expressions

filter(my_data_frame, condition)
filter(my_data_frame, condition_one, condition_two, ...)
View Interactive Version

The filter() function can take multiple filtering rules as input as well. These can be seen as a combination of rules with the & operator. In order for a row to be included in the output, all filtering rules must be fulfilled by it. In the following example, we filter the pres_results data frame for all rows where the state variable is equal to "CA" and the year variable is equal to 2016:

filter(pres_results, state == "CA", year==2016)
# A tibble: 1 x 6
   year state total_votes   dem   rep  other
  <dbl> <chr>       <dbl> <dbl> <dbl>  <dbl>
1  2016 CA       14181595 0.617 0.316 0.0581

We get a single row as output, containing the 2016 US presidential election results for California state.

Filter data frame rows