Get startedGet started for free

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.

This exercise is part of the course

Analyzing US Census Data in R

View Course

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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)
Edit and Run Code