Skip to content
Prev 10113 / 29559 Next

raster: apply() in brick objects?

Hi!

Given a brick object (longitude, latitude, time), I need a (lon,lat)
layer with the maximum value of each cell across time.
That's  the equivalent to
but for x being a brick object. How can I do it with raster?

I've tried
class       : RasterBrick
filename    :
nlayers     : 3
nrow        : 5
ncol        : 5
ncell       : 25
projection  : NA
min value   : ? ? ?
max value   : ? ? ?
extent      : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
resolution  : 0.2, 0.2  (x, y)
But the result is wrong, as it should be 1 layer and not 3:
class       : RasterBrick
filename    :
nlayers     : 3
nrow        : 5
ncol        : 5
ncell       : 25
projection  : NA
min value   : 232 232 248
max value   : 248 248 248
extent      : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
resolution  : 0.2, 0.2  (x, y)

I've also tried with stackApply(), but do not think that's the way to go.
Also, I'm concerned that apply() is typically very slow in R, and I'm
dealing with a large brick object.

Thanks

Agus