CommencerCommencer gratuitement

Tidy and wide data in tidycensus

By default, tidycensus functions return tidy data frames, in which each row represents a unique unit-variable combination. However, at times it is useful to have each Census variable in its own column for some methods of visualization and analysis. To accomplish this, you can set output = "wide" in your calls to get_acs() or get_decennial(), which will place estimates/values and margins of error in their own columns.

Cet exercice fait partie du cours

Analyzing US Census Data in R

Afficher le cours

Instructions

  • Get ACS data on median household income and median age for counties in Oregon in wide format by specifying output = "wide".
  • Check the first few rows of your wide data frame.
  • Create a scatter plot of median household income and median age with the plot() function.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Return county data in wide format
or_wide <- get_acs(geography = ___, 
                     ___ = "OR",
                     variables = c(hhincome = "B19013_001", 
                            medage = "B01002_001"), 
                     output = ___)

# Compare output to the tidy format from previous exercises
head(___)

# Create a scatterplot
___(or_wide$hhincomeE, or_wide$medageE)
Modifier et exécuter le code