Save up to $499! Grab all Python courses for $49 or all online courses we’ve ever launched for only $169. Only Feb 11-16. Happy Valentine's!
Create new variables
Grouping and statistical functions
7. Median and mean
Joining datasets


Having one statistic is not very informative. We can calculate other statistics within the same summarise() function by separating the functions with commas, as we did earlier.

Suppose we need both the median and mean populations. We could write:

countries %>%
    avg_pop = mean(population),
    median_pop = median(population))


Use summarise() along with the median() and mean() functions to calculate the average urban population and average urban population percentage (based on the urban_pop_pc column). Give the new columns the names median_urban_pop and avg_urban_pc, respectively.

Stuck? Here's a hint!


countries %>%
    median_urban_pop = median(urban_population),
    avg_urban_pc = mean(urban_pop_pc))