Skip to main content
Inserted example for accessing singe layers.
Source Link
fdetsch
  • 5.2k
  • 2
  • 32
  • 42

Have a look at nlayers(s). The returned number of layers will equal 28 - at least for the above example with 4 multi-layer objects encompassing 7 layers each. Applying stack to multiple multi-layer files results in one huge 'RasterStack' object, i.e. all the single multi-layer objects are appended to one another.

If you would like to have separate stacks for each file, I would recommend using

s <- lapply(raster_data, stack)

which results in a list of 'RasterStack' objects, each including 7 layers rather than one huge stack. You may then access particular layers, e.g. the 2nd layer of the 3rd 'RasterStack' object, by

s[[3]][[2]]

Have a look at nlayers(s). The returned number of layers will equal 28 - at least for the above example with 4 multi-layer objects encompassing 7 layers each. Applying stack to multiple multi-layer files results in one huge 'RasterStack' object, i.e. all the single multi-layer objects are appended to one another.

If you would like to have separate stacks for each file, I would recommend using

s <- lapply(raster_data, stack)

which results in a list of 'RasterStack' objects, each including 7 layers rather than one huge stack.

Have a look at nlayers(s). The returned number of layers will equal 28 - at least for the above example with 4 multi-layer objects encompassing 7 layers each. Applying stack to multiple multi-layer files results in one huge 'RasterStack' object, i.e. all the single multi-layer objects are appended to one another.

If you would like to have separate stacks for each file, I would recommend using

s <- lapply(raster_data, stack)

which results in a list of 'RasterStack' objects, each including 7 layers rather than one huge stack. You may then access particular layers, e.g. the 2nd layer of the 3rd 'RasterStack' object, by

s[[3]][[2]]
Source Link
fdetsch
  • 5.2k
  • 2
  • 32
  • 42

Have a look at nlayers(s). The returned number of layers will equal 28 - at least for the above example with 4 multi-layer objects encompassing 7 layers each. Applying stack to multiple multi-layer files results in one huge 'RasterStack' object, i.e. all the single multi-layer objects are appended to one another.

If you would like to have separate stacks for each file, I would recommend using

s <- lapply(raster_data, stack)

which results in a list of 'RasterStack' objects, each including 7 layers rather than one huge stack.