On Thu, Jun 17, 2010 at 7:27 PM, Grant Gillis <grant.j.gil...@gmail.com> wrote:
> grid1 <- readAsciiGrid("C:\\junk\\grid1.asc") > grid2 <- readAsciiGrid("C:\\junk\\grid2.asc") > > After this no luck with the "mean" command These things are SpatialGridDataFrames and can be 'cbind'ed together: > gAll = cbind(grid1,grid2) > spplot(gAll) now compute the row means and add them to the data frame: > gAll$mean = apply(g...@data[,1:2],1,mean) > spplot(gAll) Just to make sure it was doing the right thing I made some test data: > g...@data[,1]=1:100 > g...@data[,2]=100:1 > gAll$mean = apply(g...@data[,1:2],1,mean) > spplot(gAll) - which shows me two ramps in opposite directions and a very flat mean, with value: > g...@data[,3] [1] 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 [16] 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 50.5 How's that? It probably only works if the grids have the same spatial basis. If you've really got many of these, then write a loop. Barry _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo