Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. trunc( as.numeric( substr( zipvec, 1,3))/2 )
  2.  
  3. > url <- "http://www.unitedstateszipcodes.org/zip_code_database.csv"
  4. > tmp <- tempfile()
  5. > download.file(url, tmp)
  6. > zips <- read.csv("zip_code_database.csv")
  7. > unlink(tmp)
  8. > zip.sub <- zips[zips$type == "STANDARD",
  9. c("zip", "state", "latitude", "longitude")]
  10.  
  11. > zip.sub[sample(1:nrow(zip.sub), 10, FALSE), ]
  12. ## zip state latitude longitude
  13. ## 12121 28649 NC 36.33 -81.23
  14. ## 4129 11359 NY 40.79 -73.77
  15. ## 22577 51026 IA 42.23 -96.09
  16. ## 40251 95480 CA 38.64 -123.37
  17. ## 23441 53804 WI 42.89 -90.92
  18. ## 40574 96022 CA 40.33 -122.45
  19. ## 13589 31548 GA 30.79 -81.66
  20. ## 40557 96001 CA 40.60 -122.46
  21. ## 40428 95757 CA 38.35 -121.42
  22. ## 4531 12205 NY 42.66 -73.79
  23.  
  24. > trn <- trunc(as.numeric(substr(zip.sub$zip, 1,3))/2)
  25. > length(unique(trn))
  26. ## [1] 442
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement