
Rows of a GRaster or GVector's table that have no NAs or that have NAs
Source:R/complete.cases.r
complete.cases.RdWhen applied to a categorical GRaster, compete.cases() returns TRUE for each row of the "levels" table that has no NAs in it. In contrast, missing.cases() returns TRUE for each row that has at least one NA in it. If the raster is not categorical, then NA is returned.
When applied to a GVector with a data table, complete.cases() returns TRUE for each row where there are no NAs. if the GVector has no data table, then a vector of TRUE values the same length as the total number of geometries will be returned. In contrast, missing.cases() returns TRUE for every row that has at least one NA in it. If the GVector has no data table, then a vector of FALSE values is returned.
Usage
# S4 method for class 'GRaster'
complete.cases(..., levels = TRUE)
# S4 method for class 'GVector'
complete.cases(...)
# S4 method for class 'GRaster'
missing.cases(..., levels = TRUE)
# S4 method for class 'GVector'
missing.cases(...)Arguments
- ...
A
GRasterorGVector.- levels
Logical (
GRasters only): IfTRUE(default), then assess only the "value" andactiveCat()columns of the levels table (seelevels()). IfFALSE, then assess all columns (seecats()).
Value
Both complete.cases() and missing.cases() return the same type of object. The output depends on the input:
A categorical
GRasterwith just one layer: A logical vector.An integer, float, or double
GRasterwith just one layer:NA.A
GRasterwith multiple layers: A list with one element per layer with either logical vectors orNAs, as per above.A
GVectorwith a data table: A logical vector.A
GVectorwithout a data table:NA.
Examples
if (grassStarted()) {
# Setup
library(sf)
library(terra)
# Plant specimens (points) and land cover
madDypsis <- fastData("madDypsis")
madCover <- fastData("madCover")
# Convert to GVector and GRaster
dypsis <- fast(madDypsis)
cover <- fast(madCover)
### GVector
# Look at the data table:
as.data.table(dypsis)
# Which rows have no NAs?
complete.cases(dypsis)
# Which rows have at least one NA (opposite of above)?
missing.cases(dypsis)
### GRaster
# Look at the levels table:
levels(cover)
# Which rows of levels table have no NAs?
complete.cases(cover)
# Which rows have at least one NA (opposite of above)?
missing.cases(cover)
}