Skip to content
Prev 10851 / 29559 Next

Rasters average

I think the calculations could be a lot quicker if you make a raster 
stack or raster brick from your seven rasters and use that. see example 
below. Maybe you have to play around with your in memory settings and 
use a file on the disk. But i'm still able to do it using rasters upto 
200000 points easily in memory within seconds

 > (a<-brick(raster(matrix(runif(10), ncol=2)), 
raster(matrix(c(runif(8), NA, NA), ncol=2))))
class       : RasterBrick
dimensions  : 5, 2, 2  (nrow, ncol, nlayers)
ncell       : 10
resolution  : 0.5, 0.2  (x, y)
projection  : NA
extent      : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
values      : from memory
min values  : 0.015 0.015
max values  : 0.94 0.95

 > values(a[[2]])
  [1] 0.13370844 0.94727248 0.45225123 0.16531864 0.62212769 0.01502728
  [7] 0.66552310         NA 0.72266646         NA
 > values(a[[1]])
  [1] 0.41511274 0.90717270 0.59899444 0.17772793 0.93664444 0.53157684
  [7] 0.05073588 0.91242408 0.01484997 0.29561654
 > values(mean(a, na.rm=TRUE))
  [1] 0.2744106 0.9272226 0.5256228 0.1715233 0.7793861 0.2733021 0.3581295
  [8] 0.9124241 0.3687582 0.2956165
 >
On 02/09/2011 11:05 AM, luca candeloro wrote: