LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Analyzing US Census Data in R

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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)
Code bearbeiten und ausführen