#Hello - I am new to spatial stats in r.

#two lat long grids, one with higher grain, attempting to coerce the course
grid into #the fine grid through an overlay process.

#here is some sample code
x<-c(1,1.5,2,2.5,3,3.5,4,4.5,5.5)
latA<-rep(x,each=9)
y<-c(80,81,82,83,84,85,86,87,88)
lonA<-rep(y,9)
gridA<-cbind(latA,lonA)
gridA<-data.frame(gridA)

#producing:
#> gridA[1:12,]
#   latA lonA
#1   1.0   80
#2   1.0   81
#3   1.0   82
#4   1.0   83
#5   1.0   84
#6   1.0   85
#7   1.0   86
#8   1.0   87
#9   1.0   88
#10  1.5   80
#11  1.5   81
#12  1.5   82

x1<-c(1,2.6,4.2,5.8,7.4)
latB<-rep(x1,each=5)
y1<-c(80,82.1,84.2,86.3,88.4)
lonB<-rep(y1,5)
val_B<-sample(1:49,25,replace=F)
gridB<-cbind(latB,lonB,val_B)
gridB<-data.frame(gridB)

#producing:
#> gridB[1:12,]
#   latB lonB val_B
#1   1.0 80.0    40
#2   1.0 82.1     7
#3   1.0 84.2    19
#4   1.0 86.3    34
#5   1.0 88.4    36
#6   2.6 80.0    39
#7   2.6 82.1    38
#8   2.6 84.2    20
#9   2.6 86.3    29
#10  2.6 88.4     1
#11  4.2 80.0    22
#12  4.2 82.1     5
#etc....


#my objective is to add a column to gridA that contains the value from
#gridB$val_B that is closest in coordinates (lat and lon) to the coordinates
in gridA

#my actual data is about 30,000 lines long, but the method should not
change.
#I know there is an easy way to do this - is this in sp?

#thanks!
-- 
Joshua J. Tewksbury
Walker Professor of Natural History,
Department of Biology, University of Washington
106 Kincaid Hall, Box 351800
Seattle WA 98195-1800
my lab and office are in 528 Kincaid Hall
cell phone 206/331-1893,
office phone: 206/616-2129
lab phone: 206/616-2132,
fax: 206/616-2011
website: http://faculty.washington.edu/tewksjj/index.html

Please join the Natural History Network (
http://www.naturalhistorynetwork.org/)

	[[alternative HTML version deleted]]

