Learn R Programming

stars (version 0.1-1)

st_apply: st_apply apply a function to one or more array dimensions

Description

st_apply apply a function to array dimensions: aggregate over space, time, or something else

Usage

st_apply(X, MARGIN, FUN, ...)

Arguments

X

object of class stars

MARGIN

see apply

FUN

see apply

...

arguments passed on to FUN

Value

object of class stars with accordingly reduced number of dimensions; in case FUN returns more than one value, a new dimension is created carrying the name of the function used; see the examples.

Examples

Run this code
# NOT RUN {
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = read_stars(tif)
st_apply(x, 1:2, mean) # mean band value for each pixel
st_apply(x, 3, mean)   # mean of all pixels for each band
st_apply(x, 1:2, range) # min and max band value for each pixel
# }

Run the code above in your browser using DataLab