I need to aggregate a rasterbrick into monthly values. Normally, this would be easy by using zApply
function from raster
package. However, I have a large rasterbrick and this would take a very long time.
So basically, I am wondering if this would be easy to do it with some libraries like parallel
or clusterR
but I have no clue how to parallelize this process
# create a random raster stack
library(raster)
lay <- stack()
for (i in 1:365){
print(i)
ras <- matrix(rnorm(500, mean = 21, sd = rnorm(21, 12, 4)))
ras <- raster(ras)
lay <- addLayer(lay, ras)
}
dats <- seq(as.Date('2000-01-01'), length.out = nlayers(lay), by = 'days')
lay <- setZ(lay, dats)
monthlies <- zApply(lay, by = format(dats,"%m"), fun = 'mean') # aggregate from daily to monthly.
Thanks!