Learn R Programming

campfin (version 1.0.7)

normal_zip: Normalize ZIP codes

Description

Return consistent version US ZIP codes using stringr::str_*() functions. Non-number characters are removed, strings are padded with zeroes on the left (leading zeroes for New England ZIP codes are often removed by Microsoft Excel and other programs), and ZIP+4 suffixes are removed. Invalid ZIP codes from a vector can be removed as well as single (repeating) character strings.

Usage

normal_zip(zip, na = c("", "NA"), na_rep = FALSE)

Arguments

zip

A vector of US ZIP codes.

na

A vector of values to pass to na_in().

na_rep

logical; If TRUE, na_rep() will be called. Please note that 22222, 44444, and 55555 valid ZIP codes that will not be removed.

Value

A character vector of normalized 5-digit ZIP codes.

See Also

Other geographic normalization functions: abbrev_full(), abbrev_state(), check_city(), expand_abbrev(), expand_state(), fetch_city(), normal_address(), normal_city(), normal_state(), str_normal()

Examples

Run this code
# NOT RUN {
normal_zip(
  zip = c("05672-5563", "N/A", "05401", "5819", "00000"),
  na = c("", "NA"),
  na_rep = TRUE
)
# }

Run the code above in your browser using DataLab