Created
September 15, 2015 14:08
-
-
Save cigrainger/d71f8d269e88dabcb9d3 to your computer and use it in GitHub Desktop.
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
# head(postcodes) | |
# postcode latitude longitude | |
#1 SK17 53.24400 -1.879000 | |
#2 OX15 52.05515 -1.429983 | |
#3 BA8 51.01226 -2.411274 | |
#4 CB21 52.12717 0.272036 | |
#5 CA13 54.66000 -3.366000 | |
#6 CH7 53.6900 -3.133000 | |
# | |
# head(latlon) | |
# lat lon | |
#1 60.8177 -13.90909 | |
#2 60.8177 -13.70454 | |
#3 60.8177 -13.50000 | |
#4 60.8177 -13.29545 | |
#5 60.8177 -13.09091 | |
#6 60.8177 -12.88636 | |
match <- function(x,latorlon){ | |
dist <- as.matrix(pdist(x,latlon)) | |
matched <- latlon[min(dist),] | |
if(latorlon == 'lat'){ | |
return(matched$lat) | |
} | |
if(latorlon == 'lon'){ | |
return(matched$lon) | |
} | |
} | |
z <- sapply(postcodes[,c('latitude','longitude')],FUN=match,latorlon='lat') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment