[R-sig-Geo] NAvalue() from raster not working?

Pascal Oettli kridox at ymail.com
Wed Apr 9 15:39:00 CEST 2014


Hello,

In the help file of "NAvalue", it is written : "Values already in
memory will not be affected."

r <- raster(matrix(runif(100),nrow=10))
r[seq(10,100,by=10)]<- -10000
inMemory(r)
[1] TRUE

Regards,
Pascal

On Wed, Apr 9, 2014 at 10:27 PM, Agustin Lobo <alobolistas at gmail.com> wrote:
> I have raster layers with may nodata values (-10000)
> I set them as NAvalues but nothing seems to change:
>
> r <- raster(matrix(runif(100),nrow=10))
> r[seq(10,100,by=10)]<- -10000
> cellStats(r,mean)
> [1] -999.521
>
> NAvalue(r) <- -10000
> cellStats(r,mean)
> [1] -999.521
>
> Instead:
> r[r==-10000] <- NA
> cellStats(r,mean)
> [1] 0.5322636
>
> is this the intentional behaviour?
> what is NAvalues() for in that case?
> Thanks
> Agus
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan



More information about the R-sig-Geo mailing list