Great! So far, you've learned how to filter rows based on a single condition.
However, you'll sometimes want to use more than one condition for row filtering. In that case, you can use logical operators (
|) to combine multiple conditions.
For example, if you want to retrieve cities from Germany that have more than 1 million people, you can combine two conditions like this:
cities[cities$country == "Germany" & cities$population > 1000000, ]
Inside the brackets and before the comma, we defined two conditions:
cities$country == "Germany" and
cities$population > 1000000. We combine them together with the logical "and" operator (
&). This ensures that R displays only the rows that match both conditions.