crosstabDT: Speedy Raster Cross-tabulation

View source: R/crosstabDT.R

crosstabDTR Documentation

Speedy Raster Cross-tabulation

Description

A fast data.table-based alternative to raster::crosstab().

Usage

crosstabDT(x, y, digits = 0, long = FALSE, useNA = FALSE)

Arguments

x

A Raster* object

y

If x has just one layer, a RasterLayer object. Otherwise, if x is a multi-layered RasterStack or RasterBrick, this argument (if any) is unused.

digits

Integer. The number of digits for rounding the values before cross-tabulation. Default is 0.

long

Logical. If TRUE, the results are returned in a 'long' format data.table instead of as a table. Default is FALSE.

useNA

Logical. Should the returned table or data.table include counts of NA values? Default is FALSE.

Value

Either a table or a data.table recording the frequency of each combination of raster values.

Author(s)

Joshua O'Brien

Examples

r <- raster(nc = 5, nr = 5)
r[] <- runif(ncell(r)) * 2
s <- setValues(r, runif(ncell(r)) * 3)
crosstabDT(r, s)

rs <- r/s
r[1:5] <- NA
s[20:25] <- NA
x <- stack(r, s, rs)
crosstabDT(x, useNA = TRUE, long = TRUE)

rasterDT documentation built on Dec. 28, 2022, 1:57 a.m.