I have two lists of postcodes for Germany (different length). I need to find the closest postcode neighbour for each one in the first dataframe with respect to the second list. I do have longitutde and latitude information as well. It would be great to see which plz is closest, but my main interest is a distance measure (at the moment I am flexible with any distance measure). I could calculate all possible combination (2000000) and calculate their distances via geosphere
package or Google Maps DirectionFinder
(and select the smallest distance). I think I need to apply some form of https://en.wikipedia.org/wiki/Nearest_neighbor_search There are about 10.000 origins and about 200 destinations. I came across RANN
package and nn2()
with the option searchtype = priority
instead of searchtype = radius
(which I don't need).
plz city lon lat
1 69115 Heidelberg 8.6934499740601 49.406078338623
2 44137 Dortmund 7.4582135 51.5143952
3 70178 Stuttgart 9.17115 48.77426
4 68159 Mannheim 8.4696736826668 49.491940248873
5 68167 Mannheim 8.4971965 49.5038859
plz city lon lat
1 76530 Baden-Baden 8.2423068 48.7438178
2 89081 Ulm 9.961367 48.4253282
3 69120 Heidelberg 8.6752461 49.4225417
4 72076 Tübingen 9.0406256 48.5312051
5 74523 Schwäbisch-Hall 9.7424451 49.1247435