Learn R Programming

muRL (version 0.1-13)

zips: A .tab file of US ZIP code data for mapping recipients

Description

A .tab file of United States ZIP code data for mapping recipients. Called by zip.plot to match ZIP codes from letters to latitude and longitude coordinates, and then plot latitudes and longitudes on a user-selected map type.

Usage

data(zips)

Arguments

Format

A data frame with 33309 observations on 4 variables.

state

a factor containing state and territory abbreviations (with levels AK, AL, ..., WY).

zip

a factor containing three-digit, four-digit, five-digit, and three-digit-plus-wildcard formatted ZIP codes (with 33188 levels).

lat

a numeric vector of latitude coordinates.

lon

a numeric vector of longitude coordinates.

Details

A few ZIP codes span more than one state, and thus appear more than once in zips. See the Examples below for hints on extracting latitude and longitude.

References

Further information about ZIP Code Tabulation Areas (ZCTAs) is available at

http://www.census.gov/geo/ZCTA/zcta.html.

Examples

Run this code
data(zips)

summary(zips$lat)
summary(zips$lon)

## Extracting latitude and longitude.
## Create a sample survey data frame with an ID variable, 
##   respondent ZIP code, state, and survey response:
svy1 <- data.frame(id = c(1,2,3,4), zip = c("10001", "10001", "63130", "380HH"), 
          state = c("NY", "NY", "MO", "AR"), resp = c(1,2,1,5))
svy1
## Since ZIP 380HH spans three states, all are included:
svy2 <- merge(svy1, zips, by = "zip", all.x = TRUE) 
svy2
## Merging by ZIP and state omits the duplicate 380HH entries:
svy3 <- merge(svy1, zips, by = c("zip", "state"), all.x = TRUE)
svy3

Run the code above in your browser using DataLab