Looks like your grids are relatively small, so you could just sum them per row:
> ?rowSums > grids <- readGDAL("grid1.asc"); names(grids) <- "g1" > grids$g2 <- readGDAL(grids2.asc")$band1 > grids$avg <- rowSums(gr...@data, na.rm=FALSE, dims=1)/length(names(grids)) Otherwise SAGA can be very efficient in getting grid statistics for large grids e.g.: > rsaga.get.usage(lib="geostatistics_grid", module=5) [http://spatial-analyst.net/scripts/getMOD12C1.R] T. Hengl http://home.medewerker.uva.nl/t.hengl/ > -----Original Message----- > From: r-sig-geo-boun...@stat.math.ethz.ch [mailto:r-sig-geo- > boun...@stat.math.ethz.ch] On Behalf Of Grant Gillis > Sent: Thursday, June 17, 2010 8:27 PM > To: r-sig-geo@stat.math.ethz.ch > Subject: [R-sig-Geo] creating a mean of ascii grids > > Hello All, > > Thanks in advance. > > I have many ascii raster files with values representing resistance to animal > movement. I would like to merge these files into one with the cells > representing the mean cell value from all of the files but I have not found > an easy way to do this. Hopefully I haven't missed something easy. > > Example: > > grid1 > > ncols 10 > nrows 10 > xllcorner 1.0 > yllcorner 1.0 > cellsize 1.0 > NODATA_value -9999 > 0.000357 0.001027 0.000805 0.000000 0.081807 0.187900 0.104016 0.022658 > 0.009466 0.001935 > 0.003548 0.127713 0.209348 0.000000 0.223908 0.038593 0.130113 0.153949 > 0.077215 0.006899 > 0.011093 1.000000 0.431280 0.408257 0.000000 0.000000 0.110307 0.025862 > 0.137367 0.062129 > 0.034994 0.216908 0.353100 0.272441 0.377437 0.302346 0.000000 0.096949 > 0.103691 0.109096 > 0.082386 0.106230 0.143232 0.082990 0.000000 0.108077 0.303234 0.000000 > 0.028730 0.177887 > 0.038909 0.214878 0.070393 0.065658 0.069213 0.062199 0.320038 0.033622 > 0.000000 0.194666 > 0.019571 0.207906 0.072075 0.063715 0.048383 0.289683 1.000000 0.016230 > 0.203176 0.000000 > 0.024110 0.181760 0.038990 0.140245 0.184284 0.213371 0.181881 0.208175 > 0.040404 0.010333 > 0.000000 0.087435 0.181934 0.139346 0.140992 0.081971 0.005192 0.003207 > 0.001927 0.000927 > 0.000000 0.000000 0.016308 0.016914 0.012778 0.006049 0.002248 0.000651 > 0.000341 0.000197 > > grid2 > > ncols 10 > nrows 10 > xllcorner 1.0 > yllcorner 1.0 > cellsize 1.0 > NODATA_value -9999 > 0.000468 0.001199 0.000920 0.000000 0.121743 0.280769 0.161228 0.041467 > 0.018927 0.003883 > 0.003525 0.135052 0.228564 0.000000 0.332760 0.054795 0.181881 0.314980 > 0.159828 0.014272 > 0.008427 1.000000 0.437725 0.501494 0.000000 0.000000 0.234149 0.052453 > 0.384025 0.142958 > 0.024514 0.176738 0.346569 0.267034 0.399569 0.344980 0.000000 0.371773 > 1.000000 0.178494 > 0.056282 0.071736 0.096446 0.059201 0.000000 0.061408 0.233373 0.000000 > 0.036457 0.209228 > 0.026387 0.143127 0.045834 0.043704 0.041783 0.023811 0.053071 0.016786 > 0.000000 0.221727 > 0.013008 0.137858 0.047432 0.041280 0.029609 0.111149 0.105711 0.008439 > 0.222293 0.000000 > 0.015954 0.119895 0.025838 0.091063 0.117556 0.127833 0.130537 0.212232 > 0.044132 0.012076 > 0.000000 0.057663 0.119803 0.090802 0.091032 0.054078 0.005361 0.004239 > 0.003214 0.001584 > 0.000000 0.000000 0.010709 0.011090 0.008433 0.004449 0.002848 0.002021 > 0.001321 0.000456 > > > grid1 <- readAsciiGrid("C:\\junk\\grid1.asc") > grid2 <- readAsciiGrid("C:\\junk\\grid2.asc") > > After this no luck with the "mean" command > > Thank you and sorry for a potentially easy newbie question. > > G. > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo