Skip to content
Prev 23615 / 29559 Next

Monthly loop in raster stack with daily data

Thanks a lot Lo?c. I could not imagine that it would be that easy!
 Greetings,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota
On Thursday, October 29, 2015 3:44 AM, Lo?c Dutrieux <loic.dutrieux at wur.nl> wrote:
Hi Thiago,

I think zApply should get you there (for each stack independently).

library(zoo)
library(raster)

#Create a rasterStack similar to my data - same dimensions and layer names
r <- raster(ncol=360, nrow=180)
s <- stack(lapply(1:730, function(x) setValues(r, 
runif(ncell(r),min=0,max=30))))
idx <- seq(as.Date("2010/1/1"), by = "day", length.out = 730)
s <- setZ(s, idx)

fun <- function(x, na.rm) {
   sum(x > 25, na.rm)
}
zApply(s, by=as.yearmon, fun = fun)

Cheers,
Lo?c
On 10/29/2015 08:46 AM, Thiago V. dos Santos wrote:

            
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo