Create new variables
Grouping and statistical functions
8. The group_by() function
Joining datasets
Summary

Instruction

If you're familiar with R, you're probably thinking this isn't much of an upgrade. We could use:

mean(countries$population)

to do the same thing. That's why you'll usually see summarise() working with the group_by() function. SQL programmers will already know what this function is all about – group_by() divides our dataset into groups. If we want to group our data by continent, we use group_by() to create a structure like this:

The use of group_by() is pretty simple. We simply add the column(s) by which we want to group our data. Grouping our dataset by continent will look like this:

countries %>% group_by(continent)

Exercise

Group data from countries_urban by the urban_country column. What do you think will be displayed?

Stuck? Here's a hint!

Type:

countries_urban %>% group_by(urban_country)