Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trunc( as.numeric( substr( zipvec, 1,3))/2 )
- > url <- "http://www.unitedstateszipcodes.org/zip_code_database.csv"
- > tmp <- tempfile()
- > download.file(url, tmp)
- > zips <- read.csv("zip_code_database.csv")
- > unlink(tmp)
- > zip.sub <- zips[zips$type == "STANDARD",
- c("zip", "state", "latitude", "longitude")]
- > zip.sub[sample(1:nrow(zip.sub), 10, FALSE), ]
- ## zip state latitude longitude
- ## 12121 28649 NC 36.33 -81.23
- ## 4129 11359 NY 40.79 -73.77
- ## 22577 51026 IA 42.23 -96.09
- ## 40251 95480 CA 38.64 -123.37
- ## 23441 53804 WI 42.89 -90.92
- ## 40574 96022 CA 40.33 -122.45
- ## 13589 31548 GA 30.79 -81.66
- ## 40557 96001 CA 40.60 -122.46
- ## 40428 95757 CA 38.35 -121.42
- ## 4531 12205 NY 42.66 -73.79
- > trn <- trunc(as.numeric(substr(zip.sub$zip, 1,3))/2)
- > length(unique(trn))
- ## [1] 442
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement