Skip to content
Back to formatted view

Raw Message

Message-ID: <4D5D4FD3-E9EF-4871-BFE7-9C80D1F7B55A@noaa.gov>
Date: 2008-09-12T19:19:22Z
From: Roy Mendelssohn - NOAA Federal
Subject: Join data by minimum distance
In-Reply-To: <BAY104-W54C03A325F8592D130BEB5C3510@phx.gbl>

Hi Monica:

On Sep 12, 2008, at 11:59 AM, Monica Pisica wrote:

>
> 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.
>

Have you looked at the package "field".  It has distance functions.   
You would then have to do a little programming to find the minimum  
distance and add the columns.

HTH,

-Roy M.

**********************
"The contents of this message do not reflect any position of the U.S.  
Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: Roy.Mendelssohn at noaa.gov (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"