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
x = array(round(runif(n=3*4*5,min=0,max=10)),dim=c(3,4,5))
apply(x,c(1,2),max,na.rm=T)
but for x being a brick object. How can I do it with raster?
I've tried
funmax <- function(x) {apply(x,c(1,2),max,na.rm=T)}
show(br)
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