Advertisement
Guest User

r zip code lookup

a guest
May 3rd, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.42 KB | None | 0 0
  1. library(ggmap)
  2.  
  3. stations = read.delim('stations.tsv',
  4.                       header = T,
  5.                       sep = '\t')
  6.  
  7. stations$lat = as.numeric(stations$lat)
  8. stations$long = as.numeric(stations$long)
  9.  
  10. get_zip_from_latlong <- function(latlong) {
  11.   zip = levels(revgeocode(as.numeric(latlong), output="more")$postal_code)
  12.   return(zip)
  13. }
  14.  
  15. stations$zip = apply(
  16.   stations,
  17.   c(1,2),
  18.   get_zip_from_latlong
  19. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement