zi_validate {zippeR} | R Documentation |
Validate ZIP Code or ZCTA Vector
Description
This function validates vectors of ZIP Code or ZCTA values. It
is used internally throughout zippeR
for data validation, but
is exported to facilitate troubleshooting.
Usage
zi_validate(x, style = "zcta5", verbose = FALSE)
Arguments
x |
A vector containing ZIP or ZCTA values to be validated. |
style |
A character scalar - either |
verbose |
A logical scalar; if |
Details
The zi_validate()
function checks for four conditions:
Is the input vector character data? This is important because of USPS's use of leading zeros in ZIP codes and ZCTAs.
Are all values five characters (if
style = "zcta5"
, the default), or three characters (ifstyle = "zcta3"
)?Are any input values over five characters (if
style = "zcta5"
, the default), or three characters (ifstyle = "zcta3"
)?Do any input values have non-numeric characters?
The questions provide a basis for repairing issues identified with
zi_repair()
.
Value
Either a logical value (if verbose = FALSE
) or a tibble
containing validation criteria and results.
Examples
# sample five-digit ZIPs
zips <- c("63088", "63108", "63139")
# successful validation
zi_validate(zips)
# sample five-digit ZIPs in data frame
zips <- data.frame(id = c(1:3), ZIP = c("63139", "63108", "00501"), stringsAsFactors = FALSE)
# successful validation
zi_validate(zips$ZIP)
# sample five-digit ZIPs with character
zips <- c("63088", "63108", "zip")
# failed validation
zi_validate(zips)
zi_validate(zips, verbose = TRUE)