Mutating and counting
You can combine multiple verbs together to answer increasingly complicated questions of your data. For example: "What are the US states where the most people walk to work?"
You'll use the walk
column, which offers a percentage of people in each county that walk to work, to add a new column and count based on it.
counties_selected <- counties %>%
select(county, region, state, population, walk)
This exercise is part of the course
Data Manipulation with dplyr
Exercise instructions
- Use
mutate()
to calculate and add a column calledpopulation_walk
, containing the total number of people who walk to work in a county. - Use a (weighted and sorted)
count()
to find the total number of people who walk to work in each state.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
counties_selected %>%
# Add population_walk containing the total number of people who walk to work
___
# Count weighted by the new column, sort in descending order
___