The output from zi_load_crosswalk() for HUD data requires
additional processing to be used in the zi_crosswalk() function.
This function prepares the HUD data for use in joins.
Arguments
- .data
The output from
zi_load_crosswalk()with HUD data.- by
Character scalar; the column name to use for identifying the best match for a given ZIP Code. This could be either
"residential","commercial", or"total".- return_max
Logical scalar; if
TRUE(default), only the county with the highest proportion of the ZIP Code type will be returned. If the ZIP Code straddles two states, two records will be returned. IfFALSE, all records for the ZIP Code will be returned. Where a tie exists (i.e. two counties each contain half of all addresses), the county with the lowestGEOIDvalue will be returned.
Examples
# load sample crosswalk data
mo_xwalk <- zi_mo_hud
# the above data can be replicated with the following code:
# zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1,
# target = "COUNTY", query = "MO")
# prep crosswalk
# when a ZIP Code crosses county boundaries, the portion with the largest
# number of residential addresses will be returned
zi_prep_hud(mo_xwalk, by = "residential", return_max = TRUE)
#> # A tibble: 1,127 × 5
#> zip5 geoid state state_fips ratio
#> <chr> <chr> <chr> <chr> <dbl>
#> 1 72643 05009 MO 29 1
#> 2 63501 29001 MO 29 1
#> 3 63533 29001 MO 29 0.978
#> 4 63540 29001 MO 29 1
#> 5 63546 29001 MO 29 0.630
#> 6 63559 29001 MO 29 0.950
#> 7 64421 29003 MO 29 1
#> 8 64427 29003 MO 29 0.889
#> 9 64436 29003 MO 29 0.980
#> 10 64449 29003 MO 29 1
#> # ℹ 1,117 more rows