Last call! Check what courses we have in our offer, and get them all here to save $727 (only hours left.)
Introduction to data frames
Data frame structure
Accessing columns in a data frame
Accessing rows and columns combined in a data frame
Data frame analysis
27. Summary for a filtered data frame


Nice! You can also use summary on filtered data frames. For example, if Versico's management wants to examine the summary statistics of German cities with populations greater than 1 million, we can call the summary() function on a filtered data frame like this:

summary(cities[cities$country == "Germany" & cities$population > 1000000, ])

R will return the following output:

   country          ...    latitude      ...     
 Length:7           ...  Min.   :48.13   ...
 Class :character   ...  1st Qu.:49.14   ...
 Mode  :character   ...  Median :50.10   ...
                         Mean   :50.58   ...
                         3rd Qu.:51.99   ...
                         Max.   :53.55   ...

If you take a look at the population column, you will notice quite different results than those presented for the whole data frame — the minimum value is greater than 1 million, and the maximum is greater than 3 million. Of course, this is because our filtered subset only contains German cities whose populations exceed 1 million inhabitants.


Display summary statistics for countries in WESTERN EUROPE that have more than 50 million inhabitants. Call the summary() function on the filtered data frame.

Stuck? Here's a hint!

You have to apply the following filtering before:

countries[countries$region == "WESTERN EUROPE" & countries$population > 50000000, ]