Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction to data frames
Data frame structure
Accessing columns in a data frame
Accessing rows of a data frame
Accessing rows and columns combined in a data frame
Data frame analysis
Summary

Instruction

Nicely done! Let's see how we can perform row filtering by specifying certain conditions. If you would like to analyze only those cities that are in Germany, you could write the following line of code:

cities[cities$country == "Germany", ]

Inside the brackets, [...], before the comma, we defined a condition using a conditional operator (in this case, the equality operator): cities$country == "Germany". This condition will evaluate to TRUE for rows where the country is Germany and FALSE otherwise. R will retrieve only those rows for which this condition is TRUE.

Exercise

From the countries data frame, extract only those countries (rows) whose region is WESTERN EUROPE. Remember to use only uppercase letters when writing WESTERN EUROPE.

Stuck? Here's a hint!

Use countries$region == "WESTERN EUROPE" inside [...] brackets. Remember about the comma after the condition!