Last active
October 6, 2015 10:42
-
-
Save gourab5139014/d4f7f9d27317dec964b4 to your computer and use it in GitHub Desktop.
The extractLongLatData() uses the ggmap API in R to extract longitude and latitude data for a set of pincodes supplied in a csv file
This file contains 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
extractLongLatData <- function(file) | |
{ | |
library(ggmaps) #In case you dont have the package, use this command - install.packages(ggmaps, dependencies = TRUE) | |
data <- read.csv(file) | |
v <- as.list(data["pincode"]) #assuming the attribute containing the pincodes in the supplied CSV file is named "pincode" | |
pc <- sapply(v,as.character) | |
pc <- sapply(pc,function(x) { paste(x,"India", sep = " ")}) #change the argument in paste() from "India" to whichever country the pincodes belong to | |
longlatpc <- geocode(pc, source = "google") | |
library(xlsx) #In case you dont have the package, use this command - install.packages(xlsx, dependencies = TRUE) | |
write.xlsx2(longlatpc,'longlatpincode.xlsx') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment