Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Analyzing US Census Data in R

Cursus bekijken

Oefeninstructies

  • Group the ca_race dataset by the GEOID 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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 %>% 
  ___(___) %>%
  ___()
Code bewerken en uitvoeren