[R-sig-Geo] create data frame after spDists (re-posted)

swagath navin swagathnavin at gmail.com
Fri Aug 24 14:24:49 CEST 2012


Hello all, sorry for re-posting, but i got a scrub message for my first mail.

I have two spatial points data frame df1 showing sample locations and df2
meteorological stations. I am interested in finding met stations closer to
the sample stations and creating a separate data frame with sample
locations and the nearest met station.

I calculated the distances between the stations:

library(sp)

df1<-data.frame(x=seq(5.1,5.5, 0.1), y=seq(51,55,1))
df2<-data.frame(x=seq(5,5.3, 0.1), y=seq(50,53,1))

coordinates(df1)=~ x + y
coordinates(df2)=~ x + y

dist=spDists(df1, df2, longlat = FALSE)

but  how can i create a data frame with sample locations and nearest met
station as shown below:

Sample location | Nearest Met station

(5.1, 51)             | (5.1,51)

for small number of stations i can do manually, but i have around 400
sample locations and 100 met stations.

Thanks a lot for your time.

Cheers,
Navin



More information about the R-sig-Geo mailing list