r <- raster(nrow=18, ncol=36)
values(r) <- runif(ncell(r)) * 10
# works for large files
cellStats(r, 'mean')
# same, but does not work for very large files
cellStats(r, mean)
# multi-layer object
cellStats(brick(r,r), mean)
Run the code above in your browser using DataLab