zi_validate | R Documentation |
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.
zi_validate(x, style = "zcta5", verbose = FALSE)
x |
A vector containing ZIP or ZCTA values to be validated. |
style |
A character scalar - either |
verbose |
A logical scalar; if |
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 (if style = "zcta3"
)?
Are any input values over five characters (if style = "zcta5"
,
the default), or three characters (if style = "zcta3"
)?
Do any input values have non-numeric characters?
The questions provide a basis for repairing issues identified with
zi_repair()
.
Either a logical value (if verbose = FALSE
) or a tibble
containing validation criteria and results.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.