Exercise

Mapping your data

In combination with mutate(), you can use map() to append the results of your calculation to a data frame. Since the map() function always returns a vector of lists you must use unnest() to extract this information into a numeric vector.

Here you will explore this functionality by calculating the mean population of each country in the gapminder dataset.

Instructions

100 XP
  • Use map() to apply the mean() function to calculate the population mean for each country and append this new list column called mean_pop using mutate().
  • Explore the first 6 rows of pop_nested.
  • Use unnest() to convert the mean_pop list into a numeric column and save this as the pop_mean data frame.
  • Explore pop_mean using head().