Created
November 25, 2013 15:28
-
-
Save corynissen/7643035 to your computer and use it in GitHub Desktop.
Code to do the geocoding of the foodborne addresses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(RCurl) | |
| library(RJSONIO) | |
| library(ggmap) | |
| df <- read.csv("submissions-2013-11-05.csv", stringsAsFactors=F) | |
| names(df) <- tolower(names(df)) | |
| # order by id, or basically date | |
| df <- df[order(df$id),] | |
| df$lat <- df$lng <- rep(NA, nrow(df)) | |
| # do this in a loop since we have to sleep to avoid google's rate limiting | |
| for(i in 1:nrow(df)){ | |
| rest.address <- ifelse(grepl("chicago", df$restaurant.address[i], | |
| ignore.case=T), df$restaurant.address[i], | |
| paste0(df$restaurant.address[i], ", Chicago IL")) | |
| results <- geocode(rest.address) | |
| df$lng[i] <- results$lon | |
| df$lat[i] <- results$lat | |
| Sys.sleep(.35) # can't ask google for these too fast... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment