Create new variables
Grouping and statistical functions
6. Function summarise()
Joining datasets
Summary

Instruction

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))

Exercise

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:

median(object_name)

Stuck? Here's a hint!

Type:

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