Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
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))