Stacking an Existing RasterStack Several Times

My question is quite similar to, unfortunately, missed the problem qaru.site/questions/1521143 / ... . I am dealing with an object RasterStackconsisting of twelve layers (one for each month of the year), and I would like to repeat these layers ten times, eventually getting RasterStackone consisting of 120 layers with every 12th layer (i.e. layer 1 is the same as layer 13, the same as layer 25, etc.).

For replication purposes, take an example from the package raster:

library(raster)

file <- system.file("external/test.grd", package = "raster")
s <- stack(file, file, file, file, file, file, file, file, file, file, file, file)

stack(s, s, s, s, s, s, s, s, s, s)

class       : RasterStack 
dimensions  : 115, 80, 9200, 120  (nrow, ncol, ncell, nlayers)
resolution  : 40, 40  (x, y)
extent      : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:28992 +towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs 
names       : test.1.1, test.2.1, test.3.1, test.4.1, test.5.1, test.6.1, test.7.1, test.8.1, test.9.1, test.10.1, test.11.1, test.12.1, test.1.2, test.2.2, test.3.2, ... 
min values  :  128.434,  128.434,  128.434,  128.434,  128.434,  128.434,  128.434,  128.434,  128.434,   128.434,   128.434,   128.434,  128.434,  128.434,  128.434, ... 
max values  :  1805.78,  1805.78,  1805.78,  1805.78,  1805.78,  1805.78,  1805.78,  1805.78,  1805.78,   1805.78,   1805.78,   1805.78,  1805.78,  1805.78,  1805.78, ... 

Of course, this can be done manually, as in the last line of code, but it seems inconvenient to me. Any suggestions on how to achieve my goal in the best way would be greatly appreciated!

Cheers,
Florian

+4
1

mget , character , :

big.stack <- stack( mget( rep( "s" , 12 ) ) )

nlayers( big.stack )
#[1] 144

replicate(), list, mget(), list list of rasterLayers stack()...

ll <- replicate( 12 , s )

big.stack2 <- stack( ll )

identical( big.stack , big.stack2 )
#[1] TRUE
+7

All Articles