[R-sig-Geo] Multiply 2 raster without considering cells with NA

sadaoui sadaouimahrez at outlook.com
Sun May 10 00:35:57 CEST 2015


Hello, 

I try to multiply 2 raster (temperature and precipitation) with "overay"
function, but the problem at the same time it multiplies the NA values, then
it gives a false result.

I tried with this code ;

library(raster) ;
T = getData('worldclim', var='tmean', res=0.5, lon=5, lat=45)/10
MeanT=mean(T)
MeanT
# values      : -11.60833, 23.35833  (min, max)

P= getData('worldclim', var='prec', res=0.5, lon=5, lat=45)
cumulP=sum(P) #values      : 10, 2883  (min, max)

r <- overlay(MeanT, cumulP, fun=function(x,y){return(y/(x+10))})
r # values      : -108000, 318000  (min, max)

Normally I find the results : ~[0-120]

I searched this page :
http://www.inside-r.org/packages/cran/raster/docs/overlay
but is not mentioned.

it is mentioned in the  the "calc" function  but it is applicable only for a
single raster : http://www.inside-r.org/packages/cran/raster/docs/calc

Thank you in advance for helping me make a calculation between two raster
without counting NA values.

Best regards



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Multiply-2-raster-without-considering-cells-with-NA-tp7588224.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list