Spatial data on USPS ZIP Codes are not published by the U.S. Postal Service or the U.S. Census Bureau. Instead, ZIP Codes can be converted to a variety of Census Bureau geographies using crosswalk files. This function reads in ZIP Code to ZIP Code Tabulation Area (ZCTA) crosswalk files from the former UDS Mapper project, which was sunset by the American Academy of Family Physicians in early 2024. It also provides access to the U.S. Department of Housing and Urban Development's ZIP Code crosswalk files, which provide similar functionality for converting ZIP Codes to a variety of geographies including counties.
Usage
zi_load_crosswalk(zip_source = "UDS", year, qtr = NULL, target = NULL,
query = NULL, key = NULL)
Arguments
- zip_source
Required character scalar; specifies the source of ZIP Code crosswalk data. This can be one of either
"UDS"
(default) or"HUD"
.- year
Required four-digit numeric scalar for year; varies based on source. For
"UDS"
, years 2009 through 2023 are available. For"HUD"
, years 2010 through 2024 are available.- qtr
Numeric scalar, required when
zip_code
is"HUD"
. Integer value between 1 and 4, representing the quarter of the year.- target
Character scalar, required when
zip_code
is"HUD"
. Can be one of"TRACT"
,"COUNTY"
,"CBSA"
,"CBSADIV"
,"CD"
, and"COUNTYSUB"
.- query
Scalar or vector, required when
zip_code
is"HUD"
. This can be a five-digit numeric or character ZIP Code, a vector of ZIP Codes, a two-letter character state abbreviation, or"all"
.- key
Optional when
zip_code
is"HUD"
. This should be a character string containing your HUD API key. Alternatively, it can be stored in your.RProfile
ashud_key
.
Examples
# \donttest{
# former UDS mapper crosswalks
zi_load_crosswalk(zip_source = "UDS", year = 2020)
#> # A tibble: 41,099 × 6
#> ZIP PO_NAME STATE ZIP_TYPE ZCTA ZIP_JOIN_TYPE
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 00501 Holtsville NY Post Office or large volume custo… 11742 Spatial join…
#> 2 00544 Holtsville NY Post Office or large volume custo… 11742 Spatial join…
#> 3 00601 Adjuntas PR Zip Code Area 00601 Zip matches …
#> 4 00602 Aguada PR Zip Code Area 00602 Zip matches …
#> 5 00603 Aguadilla PR Zip Code Area 00603 Zip matches …
#> 6 00604 Aguadilla PR Post Office or large volume custo… 00603 Spatial join…
#> 7 00605 Aguadilla PR Post Office or large volume custo… 00603 Spatial join…
#> 8 00606 Maricao PR Zip Code Area 00606 Zip matches …
#> 9 00610 Anasco PR Zip Code Area 00610 Zip matches …
#> 10 00611 Angeles PR Post Office or large volume custo… 00641 Spatial join…
#> # ℹ 41,089 more rows
# }
if (FALSE) { # \dontrun{
# HUD crosswalks
# you will need to replace INSERT_HUD_KEY with your own key
## ZIP Code to CBSA crosswalk for all ZIP Codes
zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "CBSA",
query = "all", key = INSERT_HUD_KEY)
## ZIP Code to County crosswalk for all ZIP Codes in Missouri
zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "COUNTY",
query = "MO", key = INSERT_HUD_KEY)
## ZIP Code to Tract crosswalk for ZIP Code 63139 in St. Louis City
zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "TRACT",
query = 63139, key = INSERT_HUD_KEY)
} # }