Skip to contents

A single ZIP code in y is chosen for each ZIP code in x. By default, if exact matches are not found, common variants of ZIP codes in x are searched for in y (?zipcode_variant) If multiple variants are present in y, the selected match has the lowest absolute numeric difference from the ZIP code in x; ties are broken by OSA string distance and then by the minimum number.

Usage

match_zipcodes(
  x,
  y,
  zip_variants = TRUE,
  zip_variant = c("minus1", "plus1", "sub5", "sub4", "swap")
)

Arguments

x, y

character vectors of ZIP codes to match

zip_variants

logical; fuzzy match to common variants of x in y?

zip_variant

character vector; zipcode variant types to use when zip_variants is TRUE; see ?zipcode_variant

Value

A character vector, the same length as x, containing the selected match in y for each ZIP code in x.

Examples

match_zipcodes(
  c("45222", "45219", "45219", "45220", "45220", "", NA),
  c("42522", "45200", "45219", "45221", "45223", "45321", "")
)
#> [1] "45221" "45219" "45219" "45221" "45221" NA      NA     

match_zipcodes(
  c("45222", "45219", "45219", "45220", "45220", "", NA),
  c("42522", "45200", "45219", "45221", "45223", "45321", ""),
  zip_variants = FALSE
)
#> [1] NA      "45219" "45219" NA      NA      NA      NA