terra (version 1.0-10)

crosstab: Cross-tabulate

Description

Cross-tabulate the layers of a SpatRaster to create a contingency table.

Usage

# S4 method for SpatRaster,missing
crosstab(x, digits=0, long=FALSE, useNA=FALSE, ...)

Arguments

x

SpatRaster

digits

integer. The number of digits for rounding the values before cross-tabulation

long

logical. If TRUE the results are returned in 'long' format data.frame instead of a table

useNA

logical, indicting if the table should includes counts of NA values

...

additional arguments. none implemented

Value

A table or data.frame

See Also

freq, zonal

Examples

Run this code
# NOT RUN {
r <- s <- rast(nc=5, nr=5)
set.seed(1)
values(r) <- runif(ncell(r)) * 2
values(s) <- runif(ncell(r)) * 3
x <- c(r, s)

crosstab(x)

rs <- r/s
r[1:5] <- NA
s[20:25] <- NA
x <- c(r, s, rs)
crosstab(x, useNA=TRUE, long=TRUE)
# }

Run the code above in your browser using DataLab