Clélia, The optimal solution would depend a bit on your data. If the regions are not too large, you could loop over the zones
library(raster) lst = list() for (i in 1:nzones) { p <- rasterToPoints(r, fun=function(x){x==i}) lst[[i]] = histogram(p[,3]) } If you also have the zones as polygons you could alternatively look over the polygons and use polygonValues in stead of rasterToPoints Another, more elaborate, option could be to, in your loop, reclassify the regions raster (1 / 0 ), multiply that with the elevation data; trim the output raster, make a histogram (set maxpixels to ncell(raster)) (this may take a long time to finish) You could also first aggregate the rasters; unless you care much about the extreme values. Hope this helps, Robert On Wed, May 26, 2010 at 2:08 AM, Clélia Bilodeau <clelia.bilod...@gmail.com> wrote: > Dear list, > > I have two rasters, one is a Digital Elevation Model, and the other is > a region file. > I am looking for a method that allows me to plot the elevation > histogram or density for each region. > > My first try was to do this with a function and to use "Zonal" from > the "raster" package, but I have a very large file, so I have this > error: > "RasterLayers are too large. You can use fun='sum', 'mean', 'min', or > 'max', but not a function" > > Is there another way to do this? > > Thank you. > > _______________________________________________ > 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