Skip to content
Prev 23614 / 29559 Next

Monthly loop in raster stack with daily data

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: