Gary Sieling

Export Census ACS5 data by GEOID/block group to CSV in R

See prior posts for a list of variables

write.csv(get_acs(
          geography = "block group",
          variables = "C02003_001",
          state = "PA",
          year = 2020
      ), "C:\\Users\\gary\\pa-justice-maps-sheets\\scraping\\C02003_001.csv", row.names=FALSE)

Or as a function of the variable name,

download_data <- function(varname) {
    write.csv(get_acs(
        geography = "block group",
        variables = varname,
        state = "PA",
        year = 2020
    ), paste("C:\\Users\\gary\\pa-justice-maps-sheets\\scraping\\", varname, ".csv"), row.names=FALSE)
}
Exit mobile version