Repeat the same raster layer to create a raster stack

I am trying to create a raster stack from a raster layer, where the raster stack is the same raster layer that is repeated a certain number of times.

I can do something like this:

library(raster)
rasterstack <- addLayer(rasterlayer, rasterLayer, rasterLayer) 

and it works. However, I want the stack to be around 1000 levels. I think I could just skip, but I was wondering if there is a more complicated way to do this.

The reason I'm trying to do this is to compute the weighted average of the raster stack with data, where each level represents a different time period, and where the scales are in a different raster layer object. I hope that if I create a raster table from a weight raster layer with the same number of layers as the data, I can do something like:

  weightedmean <- weighted.mean( data.RasterStack, weights.RasterStack )
+3
source share
1 answer

Data examples

library(raster)
r <- raster(ncol=10, nrow=10, vals=1:100)

Decision

n <- 10  # number of copies
s <- stack(lapply(1:n, function(i) r)) 

Or

s <- stack(replicate(n, r))
0
source

All Articles