clean.zipcodes: clean up and standardize ZIP codes

Description Usage Arguments Value Author(s) Examples

Description

Attempts to detect and clean up suspected ZIP codes. Will strip "ZIP+4" suffixes to match format of zipcode data.frame. Restores leading zeros, converts invalid entries to NAs, and returns character vector. Note that this function does not attempt to find a matching ZIP code in the database, but rather examines formatting alone.

Usage

1

Arguments

zips

character vector of suspect entries, will be cast if non-character

Value

character vector containing cleaned ZIP codes with NAs for non-conforming entries

Author(s)

Jeffrey Breen <jeffrey@atmosgrp.com>

Examples

1
2
3
4
5
6
7
8
	
# given a mix of possible zip codes, including ZIP+4 and foreign postal codes,
# attempt to identify valid zip codes and return character vector:

zips = c(2061, "02142", 2043, "20210", "2061-2203", "SW1P 3JX", "210", '02199-1880')
	
clean.zipcodes(zips)
# [1] "02061" "02142" "02043" "20210" "02061" NA      "00210" "02199"	

Example output

[1] "02061" "02142" "02043" "20210" "02061" NA      "00210" "02199"

zipcode documentation built on May 2, 2019, 9:26 a.m.