I'm trying to do the following:
For each ordered pair of a data frame (D1) containing longitudes and
latitudes and unique point IDs, calculate the distance to every point in
another data frame (D2) also containing longitudes, latitudes and point
IDs, and return to a new variable in D1 the
From: Steve Sullivan [mailto:[EMAIL PROTECTED]
I'm trying to do the following:
For each ordered pair of a data frame (D1) containing
longitudes and latitudes and unique point IDs, calculate the
distance to every point in another data frame (D2) also
containing longitudes, latitudes
Steve Sullivan [EMAIL PROTECTED] writes:
neighbor.id - vector(length=length(D1$lat))
dist.geo - vector(length=length(D2$lat))
for(i in 1:length(neighbor.id)){
for(j in 1:length(dist.geo)){
dist.geo[j] - D1$lat[i]-D2$lat[j]}
# Yes, I know that isn't the right formula, this is just a test
For largish datasets, knn1 in package class (in the recommended VR bundle)
is probably the quickest way to do this. Something like
knn1(D1[. 1:2], D2[, 1:2], D2$ID)
On Wed, 30 Jul 2003, Roger Bivand wrote:
On Wed, 30 Jul 2003, Steve Sullivan wrote:
I'm trying to do the following: