Reputation: 13
I am working with a spatRaster of the 19 Bioclimatic variables of the WorldClim. I have to transform it to a RasterStack to check for VIF.
I already tried the raster() function, but it takes me only the first of the 19 rasters.
Thanks for your help!
Upvotes: 1
Views: 3650
Reputation: 408
The function raster()
calls only one layer (the first one) while stack()
and brick()
can call several layers.
The options are:
raster::raster()
to call the first layer only (band);
raster::stack()
to call all layers (less RAM needed);
raster::brick()
to call all layers (more efficient, and more RAM needed);
See the raster::brick()
exemple:
library(raster)
b <- brick(system.file("external/rlogo.grd", package="raster"))
b
nlayers(b)
names(b)
plot(b)
Alternatively, you can try to write the object on disk and call again (same function) raster::stack()
or raster::stack()
.
raster::stack()
:
raster::brick()
:
raster::stack()
, as the layers are stored in a single array, which facilitates reading and writing to disk, being faster and more efficient in processing, however, it occupies more RAM memory.Upvotes: 2