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

Instruction

Grouping data has no visible effect for us, but it is remembered by R. In a moment, you will see why this feature is so powerful.

Let's go back to our problem. Suppose we wanted to see how many countries are urban countries, per our earlier definition. We can do this using group_by() and count():

countries_urban %>%
  group_by(urban_country) %>%
  count()

Exercise

Find out how many countries there are in each continent. Use group_by() and count() and data from countries_urban.

Stuck? Here's a hint!

Type:

countries_urban %>% 
  group_by(continent) %>% 
  count()