compare-generics: Compare and logical methods

Compare-methodsR Documentation

Compare and logical methods


Standard comparison and logical operators for computations with SpatRasters. Computations are local (applied on a cell by cell basis). If multiple SpatRaster objects are used, these must have the same geometry (extent and resolution). These operators have been implemented:

Logical: !, &, |, isTRUE, isFALSE

Compare: ==, !=, >, <, <=, >=,, is.nan, is.finite, is.infinite

The terra package does not distinguish between NA (not available) and NaN (not a number). In most cases this state is represented by NaN.

The following method has been implemented for

(SpatExtent, SpatExtent): ==


SpatRaster or SpatExtent

See Also

all.equal, Arith-methods. See ifel to conveniently combine operations and Math-methods or app to apply any R function to a SpatRaster.


r1 <- rast(ncols=10, nrows=10)
values(r1) <- runif(ncell(r1))
r1[10:20] <- NA
r2 <- rast(r1)
values(r2) <- 1:ncell(r2) / ncell(r2)

x <-
r1 == r2 

terra documentation built on Dec. 2, 2022, 5:13 p.m.