MulaiMulai sekarang secara 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.

Latihan ini adalah bagian dari kursus

Analyzing US Census Data in R

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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 dan Jalankan Kode