[R] Join data by minimum distance

Monica Pisica pisicandru at hotmail.com
Fri Sep 12 20:59:40 CEST 2008


I am wondering if there is a function which will do a join between 2 data.frames by minimum distance, as it is done in ArcGIS for example. For people who are not familiar with ArcGIS here it is an explanation:

Suppose you have a data.frame with x, y, coordinates called track, and a second data frame with different x, y coordinates and some other attributes called classif. The track data.frame has a different number of rows than classif. I want to join the rows from classif to track in such a way that for each row in track I add only the row from classif that has coordinates closest to the coordinates in the track row (and hence minimum distance in between the 2 rows), and also add a new column which will record this minimum distance. Even if the coordinates in the 2 data.frames have same name, the values are not identical between the data.frames, so a merge by column is not what I am after.

I did an R Site Search but nothing related to this particular type of join emerged.

Thanks,

Monica

_________________________________________________________________

 Live.



More information about the R-help mailing list