[R-sig-Geo] Get map of non-NA cells of a stack
Rafael Wüest
rafael.wueest at wsl.ch
Mon Jun 25 14:42:18 CEST 2012
Hi Johannes,
I don't know of any special function, but you can easily obtain this by combining sum() and is.na() . See the example below:
r <- raster(ncols=36, nrows=18)
r[] <- 1:ncell(r)
r1<-r;r1[sample(1:ncell(r1),20)]<-NA
r2<-r;r2[sample(1:ncell(r2),20)]<-NA
r3<-r;r3[sample(1:ncell(r3),20)]<-NA
s<-stack(r1,r2,r3)
s<-addLayer(s,!is.na(sum(s)))
plot(s)
This may not be the most efficient way to come up with what you want, as summing a big stack may take quite some time, but for small rasters, stacks it certainly works...
HTH, Rafi
On 25.06.2012, at 10:30, Johannes Radinger wrote:
> Hi,
>
> I have several stacks with different numbers of raster maps. All the stacked rasters have some NA-cells but sometimes in different locations. I'd like to create a raster map of a single stack which indicates cells that are populated in all rasters of that stack (all non-NA cells).
>
> Is there a special function within the raster package?
>
> Best regards
> Johannes
> --
>
> Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Rafael Wüest
Swiss Federal Research Institute WSL
Zürcherstrasse 111
8903 Birmensdorf
Switzerland
+41 44 7392126
rafael.wueest at wsl.ch
http://www.wsl.ch/info/mitarbeitende/wueest/index_EN
More information about the R-sig-Geo
mailing list