Takes raw output from tidycensus::get_acs() (B01001 table) and transforms it into tidy format with age, gender, population, and year columns.

map_acs_b01001_to_age_sex(acs_raw_df)

Arguments

acs_raw_df

Data frame with columns: GEOID, NAME, variable, estimate, moe, year

  • Typically output from tidycensus::get_acs(table = "B01001", ...)

  • Must include year column

Value

Data frame with columns: age, gender, population, year (sorted by year, then gender, then age)

  • age: Age group label

  • gender: "Male" or "Female"

  • population: Population estimate (numeric)

  • weight: Population weight (population / total_population)

  • year: Year of estimate

Details

Filters to only B01001 age-gender variables (excludes B01001_001 total and subtotals). Validates output: exactly 46 rows per year (23 age groups × 2 genders).