Mask values in a Raster object
Create a new Raster* object that has the same values as x
, except for the cells that are NA
(or other maskvalue
) in a 'mask'. These cells become NA
(or other updatevalue
). The mask can be either another Raster* object of the same extent and resolution, or a Spatial* object (e.g. SpatialPolygons) in which case all cells that are not covered by the Spatial object are set to updatevalue
. You can use inverse=TRUE
to set the cells that are not NA
(or other maskvalue
) in the mask, or not covered by the Spatial* object, to NA
(or other updatvalue
).
## S4 method for signature 'RasterLayer,RasterLayer' mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...) ## S4 method for signature 'RasterStackBrick,RasterLayer' mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...) ## S4 method for signature 'RasterLayer,RasterStackBrick' mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...) ## S4 method for signature 'RasterStackBrick,RasterStackBrick' mask(x, mask, filename="", inverse=FALSE, maskvalue=NA, updatevalue=NA, updateNA=FALSE, ...) ## S4 method for signature 'Raster,Spatial' mask(x, mask, filename="", inverse=FALSE, updatevalue=NA, updateNA=FALSE, ...)
x |
Raster* object |
mask |
Raster* object or a Spatial* object |
filename |
character. Optional output filename |
inverse |
logical. If |
maskvalue |
numeric. The value in |
updatevalue |
numeric. The value that cells of |
updateNA |
logical. If |
... |
additional arguments as in |
Raster* object
r <- raster(ncol=10, nrow=10) m <- raster(ncol=10, nrow=10) values(r) <- runif(ncell(r)) * 10 values(m) <- runif(ncell(r)) m[m < 0.5] <- NA mr <- mask(r, m) m2 <- m > .7 mr2 <- mask(r, m2, maskvalue=TRUE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.