Reputation: 3663
I'm trying to query data with the R package "censusapi."
The following code...
getCensus(
name = "sf1",
vars = c("P0010001"),
region = "zip code tabulation area:*",
vintage = 2010,
key = Sys.getenv("CENSUS_KEY")
)
...throws this error...
Error: error: unknown/unsupported geography heirarchy
.
Any idea what I need to fix here so I can get 2010 population data for every ZCTA5? Replacing "zip code tabulation area:*"
with `"county:*" works fine, by the way...
Upvotes: 1
Views: 3526
Reputation: 16871
Take a look at the Census API documentation. ZCTA is nested under states in the geography hierarchy. Seems a little odd, since normally ZCTAs are supposed to be independent of states or counties. The more "pure" ZCTA has a level number 860; the one nested under states has level 871. I have no idea how much they may differ.
So for ZCTAs, you need to give it a state in regionin
, like:
censusapi::getCensus("sf1",
vars = c("P0010001"),
region = "zip code tabulation area:*",
vintage = 2010,
key = Sys.getenv("CENSUS_KEY"),
regionin = "state:09")
If you needed zips for every state, you might be stuck apply
ing or map
ping over all states' FIPS codes and plugging into regionin
.
Upvotes: 1