You mean something like this? Basically I just wrapped a function around
extract.

library(raster)

r1 <- raster(matrix(runif(9), ncol = 3))
r2 <- raster(matrix(runif(9), ncol = 3))
r3 <- raster(matrix(runif(9), ncol = 3))
r <- stack(r1, r2, r3)

cellvals <- extract(r, 3)
which(cellvals == max(cellvals))

getStats <- function(cell, x, fun) {
  getvals <- extract(x, cell)
  ind <- which(getvals == fun(getvals))
  getvals[, ind, drop = FALSE]
}

sapply(1:3, getStats, fun = max, x = r)

Cheers,
Roman



On Sat, Mar 8, 2014 at 2:21 PM, Maurizio Marchi
<mauriziomarchi85@gmail.com>wrote:

> Hallo everybody.
> Is there a way to see in a rasterstack with the raster package which layer
> has the higer value for a selected pixel?
> I have a rasterstack with 22 raster layers and I would like to have an
> unique raster with, for each pixel, the maximum value of 22 rasters.
> For example:
> Pixel number 12345 , maximum value is 9876 from layer number XX.
>
> I hope to be clear enough...
> Bests,
> Maurizio
>
>
> --
> Maurizio Marchi
> ID skype: maurizioxyz
> *Ubuntu 12.04 LTS*
> *"Il bello dell'open-source è che le domande possono essere poste alla
> fonte"*
> *utente linux 552.742*
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


-- 
In God we trust, all others bring data.

	[[alternative HTML version deleted]]

