You should use `stackApply`.

library(raster)

fn <- system.file("external/test.grd", package="raster")
s <- stack(fn, fn)

stackApply(s, indices = 1:nlayers(s), fun = mean)

Cheers,
Roman


On Tue, Aug 6, 2013 at 10:53 AM, Carlos Vázquez <ganimedes5@hotmail.com>wrote:

> Hi to all,
> I have a problem using raster stacks in R.
> I have a set of raster layers with pixel reliability information for NDVI
> with pixel values of 0,1,2, and 3
> Since i am not interested in values 2 and 3, I want to change all 2 and 3
> values in the raster layers to NA's
> I am using the following formula:
>
>  NDVI[NDVI==3|NDVI==2]<-NA
>
>
> It works fine for single rasters but when applying to a raster stack, it
> gives strange results, converting some 0 and 1 values to NA as well.
>
> Any ideas of what might be wrong?
> Any help will be appreciated.
>
> Thanks in advance!
>
> MSc. student
>
> Carlos  Vázquez
>
>         [[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]]

