This function queries the USPS Crosswalks API provided by US Department of Housing and Urban Development (HUD USER).
Usage
hud_cw(
type,
query,
year = format(Sys.Date() - 365, "%Y"),
quarter = 1,
minimal = FALSE,
key = Sys.getenv("HUD_KEY"),
to_tibble = getOption("rhud_use_tibble", FALSE)
)
Arguments
- type
Must be a number between 1 and 12 depending on the USPS Crosswalk type. You can also supply the string name.
zip-tract
zip-county
zip-cbsa
zip-cbsadiv (Available 4th Quarter 2017 onwards)
zip-cd
tract-zip
county-zip
cbsa-zip
cbsadiv-zip (Available 4th Quarter 2017 onwards)
cd-zip
zip-countysub (Available 2nd Quarter 2018 onwards)
countysub-zip (Available 2nd Quarter 2018 onwards)
- query
5 digit USPS ZIP code of the data to retrieve. E.g. 22031 for type 1 to 5 and 11 . or 11 digit unique 2000 or 2010 Census tract GEOID consisting of state FIPS + county FIPS + tract code. Eg: 51059461700 for type 6 or 5 digit unique 2000 or 2010 Census county GEOID consisting of state FIPS + county FIPS. Eg: 51600 for type 7 or 5 digit CBSA code for Micropolitan and Metropolitan Areas Eg: 10380 for type 8 or 5-digit CBSA Division code which only applies to Metropolitan Areas. Eg: 35614 for type 9 or 4-digit GEOID for the Congressional District which consists of state FIPS + Congressional District code. Eg: 7200 for type 10 or 10-digit GEOID for the County sub Eg: 4606720300 for type 12
- year
Gets the year that this data was recorded. Can specify multiple years. Default is the previous year.
- quarter
Gets the quarter of the year that this data was recorded. Defaults to the first quarter of the year.
- minimal
Return just the crosswalked GEOIDs if true. Otherwise, return all fields. This does not remove duplicates.
- key
The key obtained from HUD (US Department of Housing and Urban Development) USER website.
- to_tibble
If TRUE, return the data in a tibble format rather than a data frame.
Value
This function returns a dataframe containing crosswalk data for one geoid to another for all combinations of "query", "year", and "quarter" inputs where query depends on type specified. These measurements include res-ratio, bus-ratio, oth-ratio, tot-ratio. For more details on these measurements, visit https://www.huduser.gov/portal/dataset/uspszip-api.html
Examples
if (FALSE) {
hud_cw(type = 1, query = "35213", year = c("2010", "2011"),
quarter = c("1"))
hud_cw(type = "2", query = "35213", year = c("2016", "2020"),
quarter = c("2"))
hud_cw(type = 3, query = 35213, year = c("2012", "2011"),
quarter = c("3"))
hud_cw(type = 4, query = "22031", year = c("2017", "2019"),
quarter = c("4"))
hud_cw(type = "5", query = "35213", year = c(2011, "2012"),
quarter = c("1", "2"))
hud_cw(type = 6, query = "48201223100", year = c("2017", "2010"),
quarter = c("1", "2", "3"))
hud_cw(type = 7, query = "22031", year = c("2010", "2011"),
quarter = c("1", "2", "3"))
hud_cw(type = 8, query = "10140", year = c("2010", "2011"),
quarter = c("1", "2"))
hud_cw(type = 9, query = "10380", year = c("2017"),
quarter = c("4"))
hud_cw(type = 10, query = "2202", year = c("2010", "2011"),
quarter = c("4", "3"))
hud_cw(type = 11, query = "35213", year = c("2019", "2020"),
quarter = c("2", "3"))
hud_cw(type = 12, query = "4606720300 ", year = c("2019", "2019", "2019"),
quarter = c("4", "4"))
}