Skip to content
Prev 7710 / 29559 Next

overlay() in raster package

Oliver,

The function passed to overlay should be work if the arguments are
vectors; but your function only works if the arguments are single
numbers.

Rather than this:

fun = function(x,y) {
	if (is.na(x))  {
		if (y==1)  { return(0)
		} else { return(x) }
	} else { return(x)	}
}


Do this:

fun = function(x,y) {
	x[is.na(x) & y==1] <- 0
	return(x)
}



Robert

On Thu, Feb 25, 2010 at 7:23 AM, Wearn, Oliver
<oliver.wearn08 at imperial.ac.uk> wrote: