Description Usage Arguments Value See Also Examples
Apply a function on subsets of a RasterStack or RasterBrick. The layers to be combined are indicated with the vector indices
.
The function used should return a single value, and the number of layers in the output Raster* equals the number of unique values in indices
.
For example, if you have a RasterStack with 6 layers, you can use indices=c(1,1,1,2,2,2)
and fun=sum
. This will return a RasterBrick with two layers. The first layer is the sum of the first three layers in the input RasterStack, and the second layer is the sum of the last three layers in the input RasterStack. Indices are recycled such that indices=c(1,2)
would also return a RasterBrick with two layers (one based on the odd layers (1,3,5), the other based on the even layers (2,4,6)).
See calc
if you want to use a more efficient function that returns multiple layers based on _all_ layers in the Raster* object.
1 | stackApply(x, indices, fun, filename='', na.rm=TRUE, ...)
|
x |
Raster* object |
indices |
integer. Vector of length |
fun |
function that returns a single value, e.g. |
na.rm |
logical. If |
filename |
character. Optional output filename |
... |
additional arguments as for |
A new Raster* object, and in some cases the side effect of a new file on disk.
1 2 3 4 5 6 7 8 |
Loading required package: sp
class : RasterBrick
dimensions : 10, 10, 100, 2 (nrow, ncol, ncell, nlayers)
resolution : 36, 18 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84
data source : in memory
names : index_1, index_2
min values : 6, 15
max values : 600, 1500
class : RasterBrick
dimensions : 10, 10, 100, 3 (nrow, ncol, ncell, nlayers)
resolution : 36, 18 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84
data source : in memory
names : index_1, index_2, index_3
min values : 5, 7, 9
max values : 500, 700, 900
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.