Learn R Programming

terra (version 0.5-2)

freq: Frequency table

Description

Frequency table of the values of a SpatRaster. NAs are not counted.

Usage

# S4 method for SpatRaster
freq(x, bylayer=TRUE, ...)

Arguments

x

SpatRaster

bylayer

logical. If TRUE tabulation is done by layer

...

additional arguments (none implemented)

Value

matrix with 2 columns (value, count) or, if bylayer=TRUE three layers (layer, value, count).

See Also

freq

Examples

Run this code
# NOT RUN {
r <- rast(nrow=10, ncol=10)
set.seed(2)
values(r) <- sample(5, ncell(r), replace=TRUE)

freq(r, FALSE)
freq(r)

x <- c(r, r/2)
freq(x, FALSE)
freq(x)

freq(round(x))
# }

Run the code above in your browser using DataLab