Skip to content
Prev 19475 / 29559 Next

Creating a maximum raster layer from RasterStack

What about this:
r1 <- raster(matrix(rnorm(100,5,10),10,10))
r2 <- raster(matrix(rnorm(100,2,30),10,10))
s <- stack(r1,r2)
mx <- stackApply(s,max)

which.max() fails because raster requires the na.rm argument (I think, Robert?)

mxd <- stackApply(s,indices=c(1,1),which.max)
Error in FUN(newX[, i], ...) : unused argument (na.rm = TRUE)

so make your own function icluding the na.rm argument:

miwhichmax <- function(x,na.rm=TRUE) which.max(x)
mxd <- stackApply(s,indices=c(1,1),miwhichmax)

Agus
On Thu, Oct 3, 2013 at 6:55 PM, Eddie Smith <eddieatr at gmail.com> wrote: