Learn R Programming

raster (version 2.0-41)

crosstab: Cross-tabulate

Description

Cross-tabulate two RasterLayer objects, or mulitiple layers in a RasterStack or RasterBrick to create a contingency table.

Usage

## S3 method for class 'RasterLayer,RasterLayer':
crosstab(x, y, digits=0, long=FALSE, progress, ...)

## S3 method for class 'RasterStackBrick,missing':
crosstab(x, digits=0, long=FALSE, progress, ...)

Arguments

x
Raster* object
y
RasterLayer if x is a RasterLayer; missing if x is a RasterStack or RasterBrick
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
progress
Character. "text", "window", or "" (the default, no progress bar), only for large files that cannot be processed in one step
...
Additional arguments that can be passed on to table, such as useNA="always" to include NA values in the tabulation (the dnn argument is ignored and using it may lead to an error)

Value

  • A table or data.frame

See Also

freq, zonal

Examples

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

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

Run the code above in your browser using DataLab