Introduction
Filtering by row
Extracting data by column
Practice using filter() and select()
The pipe operator
Sorting rows
Summary
29. Exercise 4

Instruction

We only want to see the five most populous countries. To do this, we can use head() and a pipe operator:

countries %>%
  head(5)

Exercise

Filter countries from Africa and North America. Then, select the population and country_name columns. Using arrange() and head(), display the top five countries (i.e., the five most populous countries). Caution: You'll have to reverse the sorting order.

Stuck? Here's a hint!

Type:

countries %>%
  filter(continent %in% c("Africa", "North America")) %>%
  select(country_name, population) %>%
  arrange(desc(population)) %>%
  head(5)