[R] nested for() loops for returning a nearest point

2003-07-30 Thread Steve Sullivan
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

RE: [R] nested for() loops for returning a nearest point

2003-07-30 Thread Liaw, Andy
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

Re: [R] nested for() loops for returning a nearest point

2003-07-30 Thread Peter Dalgaard BSA
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

Re: [R] nested for() loops for returning a nearest point

2003-07-30 Thread Prof Brian Ripley
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: