ifel {raster} | R Documentation |
This functions like ifelse
but this one works for Raster* objects. This is "syntactic sugar", that is, it can be easier to express what is desired; but there is no real need for it, as you can achieve the same things with combinations of calc
, reclassify
, mask
, and cover
.
In ArcMap (arcpy), ifel
is called Con
.
## S4 method for signature 'Raster' ifel(test, yes, no, filename, ...)
test |
Raster* object |
yes |
Raster* object or numeric |
no |
Raster* object or numeric |
filename |
character. Output filename (optional) |
... |
if |
This is a new method that has not been tested much yet. User beware.
Raster* object
r <- raster(nrows=5, ncols=5, vals=-10:14) x <- ifel(r > 1, 1, r) # same as a <- reclassify(r, cbind(1, Inf, 1)) b <- calc(r, function(i) {i[i > 1] <- 1; i}) d <- clamp(r, -Inf, 1) y <- ifel(r > 1, 1, ifel(r < -1, -1, r)) z <- ifel(r > -2 & r < 2, 100, 0) k <- ifel(r > 0, r+10, ifel(r < 0, r-10, 3)) plot(k) text(k)