zi_crosswalk {zippeR} | R Documentation |
Crosswalk ZIP Codes with UDS, HUD, or a Custom Dictionary
Description
This function compares input data containing ZIP Codes with a crosswalk file that will append ZCTAs. This is an important step because not all ZIP Codes have the same five digits as their enclosing ZCTA.
Usage
zi_crosswalk(.data, input_var, zip_source = "UDS", source_var,
source_result, year = NULL, qtr = NULL, target = NULL, query = NULL,
by = NULL, return_max = NULL, key = NULL, return = "id")
Arguments
.data |
An "input object" that is data.frame or tibble that contains ZIP Codes to be crosswalked. |
input_var |
The column in the input data that contains five-digit ZIP Codes. If the input is numeric, it will be transformed to character data and leading zeros will be added. |
zip_source |
Required character scalar or data frame; specifies the
source of ZIP Code crosswalk data. This can be one of either |
source_var |
Character scalar, required when |
source_result |
Character scalar, required when |
year |
Optional four-digit numeric scalar for year; varies based on source.
For |
qtr |
Numeric scalar, required when |
target |
Character scalar, required when |
query |
Scalar or vector, required when |
by |
Character scalar, required when |
return_max |
Logical scalar, required when |
key |
Optional when |
return |
Character scalar, specifies the type of output to return. Can be
one of |
Value
A tibble
with crosswalk values (or optionally, the full
crosswalk file) appended based on the return
argument.
Examples
# create sample data
df <- data.frame(id = c(1:3), zip5 = c("63005", "63139", "63636"))
# UDS crosswalk
zi_crosswalk(df, input_var = zip5, zip_source = "UDS", year = 2022)
# HUD crosswalk
zi_crosswalk(df, input_var = zip5, zip_source = "HUD", year = 2023,
qtr = 1, target = "COUNTY", query = "MO", by = "residential",
return_max = TRUE)
# custom dictionary
## load sample crosswalk data to simulate custom dictionary
mo_xwalk <- zi_mo_hud
# prep crosswalk
# when a ZIP Code crosses county boundaries, the portion with the largest
# number of residential addresses will be returned
mo_xwalk <- zi_prep_hud(mo_xwalk, by = "residential", return_max = TRUE)
## crosswalk
zi_crosswalk(df, input_var = zip5, zip_source = mo_xwalk, source_var = zip5,
source_result = geoid)