ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Analyzing US Census Data in R

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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)
Editar y ejecutar código