Finding the largest group by county
tidyverse
data wrangling tools in packages like dplyr
and purrr
are extremely powerful for exploring Census data. tidycensus
is specifically designed with data exploration within the tidyverse in mind. For example, users might be interested in finding out the largest racial/ethnic group within each county for a given state. This can be accomplished using dplyr
grouping capabilities, which allow users to identify the largest ACS group estimate and filter to retain the rows that match that group.
This exercise is part of the course
Analyzing US Census Data in R
Exercise instructions
- Group the
ca_race
dataset by theGEOID
column. - Filter the dataset to retain those rows where the
estimate
value is equal to the maximum for its group (the county). - Use the
tally()
function to determine the breakdown of largest racial/ethnic groups for counties in California.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Group the dataset and filter the estimate
ca_largest <- ___ %>%
group_by(___) %>%
filter(___ == max(estimate))
head(ca_largest)
# Group the dataset and get a breakdown of the results
ca_largest %>%
___(___) %>%
___()