Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

r: zApply in parallel computing

$
0
0

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!


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>