Created by: David Ellis
Population Health Management
Birmingham City Council
devtools::install_github("BCC-PHM/wmSpatial")# Birmingham Council House
df1 <- data.frame(postcode = "B1 1BB")
# 5 Random West Midlands Postcodes
df2 <- data.frame(
postcode = c("B36 9ST", "B96 6DD", "B70 7EJ",
"DY8 3YD", "B21 8BQ")
)
# Find the TWO (n=2) postcodes nearest to the council house
nearest_postcode(df1, df2, n = 2)Returns:
postcode latitude longitude local_authority nearest_pc_1 nearest_pc_2
1 B1 1BB 52.48043 -1.903448 Birmingham B21 8BQ B70 7EJ
The distance in km can also be calulated using distance = TRUE:
# Find the TWO (n=2) postcodes nearest to the council house with distances
nearest_postcode(df1, df2, n = 2, distance = TRUE)Returns:
postcode latitude longitude local_authority nearest_pc_1 dist_km_1 nearest_pc_2 dist_km_2
1 B1 1BB 52.48043 -1.903448 Birmingham B21 8BQ 4.53 B70 7EJ 7.09
This repository is dual licensed under the Open Government v3 & MIT. All code can outputs are subject to Crown Copyright.