Split dataframe column into 2 based on row content in R

32 views Asked by At

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.

0

There are 0 answers