Return consistent version US ZIP codes using stringr::str_*() functions.
Non-number characters are removed, strings are padded with zeroes on the
left, 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, pad = FALSE)
Value
A character vector of normalized 5-digit ZIP codes.
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.
pad
logical; Should ZIP codes less than five digits be padded with a
leading zero? Leading zeros (as are found in New England ZIP codes) are
often dropped by programs like Microsoft Excel when parsed as numeric
values.