zip_clean: Clean Zip Codes

View source: R/zip_clean.R

zip_cleanR Documentation

Clean Zip Codes

Description

This function takes a dataframe or vector containing zip codes and convert them to the standard five-digit zip codes. Depending on the argument, it saves the subdigits.

Usage

zip_clean(df, zip_var = NULL, keep_last_four = FALSE, last_four_label = NULL)

Arguments

df

Input dataframe or vector.

zip_var

Variable that contains zip codes, if df is dataframe.

keep_last_four

Whether to keep the last four digits.

last_four_label

Variable to store last four digits of zip, if any.

Examples

zip_clean(
  c("1000-2000", NA, "91125", "911250401", "800", "A", "100A"),
  zip_var = "contributor_zip", keep_last_four = TRUE,
  last_four_label = "contributor_zip_last4"
)


sysilviakim/Kmisc documentation built on Jan. 28, 2023, 10:58 a.m.