Dear Thiago, is this what you need? #### library(raster) r <- raster() r[]<-1:ncell(r) r2 <- raster() r2[]<-ncell(r):1 r <-brick(r,r2) plot(r)
sos <- calc(r,sum) x11() plot(sos) #### Matteo sos <- calc(r,sum) plot(sos) >>> Thiago Veloso 11.05.12 23.29 Uhr >>> Dear R-colleagues, I am trying to sum all layers of a RasterStack object, which is summarized below: > s class : RasterStack dimensions : 5568, 8289, 46153152, 46 (nrow, ncol, ncell, nlayers) resolution : 0.00898, 0.00898 (x, y) extent : -104.4326, -29.99736, -40.00064, 10 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 min values : -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, ... max values : 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, ... layer names : gpp2004001.Gpp_1km, gpp2004009.Gpp_1km, gpp2004017.Gpp_1km, gpp2004025.Gpp_1km, gpp2004033.Gpp_1km, gpp2004041.Gpp_1km, gpp2004049.Gpp_1km, gpp2004057.Gpp_1km, gpp2004065.Gpp_1km, gpp2004073.Gpp_1km, gpp2004081.Gpp_1km, gpp2004089.Gpp_1km, gpp2004097.Gpp_1km, gpp2004105.Gpp_1km, gpp2004113.Gpp_1km, ... The raster 's' is composed by 46 satellite images at a resolution of 1km (0.00898degree). Each layer is a 8-day composition of leaf area index and I need to integrate an entire year of LAI. When I try to run the "rowSums" function in this RasterStack, the following error is displayed: > sos <- rowSums(s,na.rm=FALSE) Error in rowSums(s, na.rm = FALSE) : 'x' must be an array of at least two dimensions The same occurs when I try to use .rowSums providing matrix dimensions: > sos <- .rowSums(s,5568,8289) Error in .rowSums(s, 5568, 8289) : 'x' must be numeric What am I doing wrong? Is there another way to integrate the layers of a RasterStack object? Thanks in advance, Thiago Veloso. P.S.: Attaching sessionInfo output to provide useful information: > sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ncdf_1.6.6 rgdal_0.7-11 raster_1.9-92 sp_0.9-99 loaded via a namespace (and not attached): [1] grid_2.15.0 lattice_0.20-6 _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo