An input ZIP code is used to generate variants (for, e.g., 45220):
minus1: subtracting one from zipcode (45219)plus1: adding one to zipcode (45221)sub5: substituting the fifth digit of the ZIP code (45221, 45222, 45223, 45224, 45225, 45226, 45227, 45228, 45229)sub4: substituting the fourth digit of the ZIP code (45200, 45210, 45230, 45240, 45250, 45260, 45270, 45280, 45290)swap: swapping the second and third digits of the ZIP code (42520)
More than one variant type can be created at once and variants will be returned in the same order as they were requested (see examples).
Usage
zipcode_variant(x, variant = c("minus1", "plus1", "sub5", "sub4", "swap"))Examples
zipcode_variant("45220")
#> [1] "45219" "45221" "45222" "45223" "45224" "45225" "45226" "45227" "45228"
#> [10] "45229" "45200" "45210" "45230" "45240" "45250" "45260" "45270" "45280"
#> [19] "45290" "42520"
# order matters!
zipcode_variant("45220", c("minus1", "plus1"))
#> [1] "45219" "45221"
zipcode_variant("45220", c("plus1", "minus1"))
#> [1] "45221" "45219"
zipcode_variant("45220", "sub5")
#> [1] "45221" "45222" "45223" "45224" "45225" "45226" "45227" "45228" "45229"
zipcode_variant("45220", "swap")
#> [1] "42520"