0

I'm using tidy census and I have 2 variables for each census tract which makes my data frame look like this:

GEOID tract variable estimate
24005400100 Tract 4001 white_pop 3436
24005400100 Tract 4001 black_pop 98

but I want my variables as separate columns with their estimate as the row content:

GEOID tract white_pop black_pop
24005400100 Tract 4001 3436 98

This is my code to load in the data:

BA_2009_data = get_acs(geography = "tract", 
                  state = "MD",
                  county = "Baltimore County",
                  variables = c(white_pop = "B02008_001", black_pop = "B02009_001"),
                  year = 2009)

I'm fairly new to R, so I am not sure how to work with this.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Kylee
  • 41
  • 5
  • Using `data.table` - `dcast(setDT(df), GEOID + tract~variable, value.var = 'estimate')` Or `tidyr::pivot_wider(df, names_from = variable, values_from = estimate)` – Ronak Shah Jun 04 '21 at 03:32
  • Use the argument `output = "wide"` in `get_acs()` - this is all you have to do! – kwalkertcu Jun 04 '21 at 18:11

0 Answers0