Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Create new variables
Grouping and statistical functions
6. Function summarise()
Joining datasets


So now that we've got the basics of dplyr, let's move on to some statistical functions.

We'll start with summarise(), which condenses or summarizes information into a single row. We can use it when we compute the mean population and store it in avg_pop column:

countries %>%
  summarise(avg_pop = mean(population))


Compute the median population for all the countries in our dataset. Use the median() function as an argument to summarise(), and name the resulting column median_pop.

Note: The base R function median() returns the middle value of a set when all values are sorted in ascending order. It looks like this:


Stuck? Here's a hint!


countries %>%
  summarise(median_pop = median(population))