7.4 Logical operators

Logical operators allow you to build more complex boolean conditions.

  • |: or
  • &: and

Filter the month from the flights dataset where the month is 11 (November) or 12 (December)

The below code will not run like you would expect (even though this is how you would say it in your head)

Instead of writing out each boolean statment separately using |, you can use the %in% operator

WIth filter, you can also specify multiple condition (like an &)

by default filter will also drop missing values. See the r4ds chapter for this.