| na.omit,GRaster-method | R Documentation |
'na.omit()' returns a GRaster stack with the same number of layers as the input, but with all cells that have NA in any layer set to NA in all layers. This is useful for masking out areas where data are missing in any of the rasters.
## S4 method for signature 'GRaster'
na.omit(object, verbose = FALSE)
object |
A "stack" of |
verbose |
Logical: If |
A GRaster.
terra::na.omit(), stats::na.omit(), GRASS tool r.mapcalc (see grassHelp("r.mapcalc"))
if (grassStarted()) {
# Setup
library(terra)
### Mask layer-by-layer
# Elevation raster
madElev <- fastData("madElev")
madForest2000 <- fastData("madForest2000")
# Convert SpatRasters to GRasters:
elev <- fast(madElev)
forest2000 <- fast(madForest2000)
# Make a random layer and stack it with elevation:
x <- c(elev, forest2000)
# Put NAs in cells where any layer has an NA:
masked <- na.omit(x, verbose = TRUE)
plot(masked)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.