freq: Frequency table

Description Usage Arguments Value Examples

Description

Frequency table of the values of a SpatRaster. NAs are not counted unless value=NA.

Usage

1
2
## S4 method for signature 'SpatRaster'
freq(x, digits=0, value=NULL, bylayer=TRUE, usenames=FALSE)

Arguments

x

SpatRaster

digits

integer. Used for rounding the values before tabulation. Ignored if NA

value

numeric. An optional single value to only count the number of cells with that value. This value can be NA

bylayer

logical. If TRUE tabulation is done by layer

usenames

logical. If TRUE layers are identified by their names instead of their numbers. Only relevant if bylayer is TRUE

Value

matrix or data.frame with 3 columns (layer, value, count) or, if bylayer=FALSE two columns (value, count). If any of the layers of x is categorical, there is an additional column (label). A data.frame is returned if usenames=TRUE or if any of the layers of x is categorical.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
r <- rast(nrows=10, ncols=10)
set.seed(2)
values(r) <- sample(5, ncell(r), replace=TRUE)

freq(r)

x <- c(r, r/3)
freq(x, bylayer=FALSE)
freq(x)

freq(x, digits=1)
freq(x, digits=-1)

freq(x, value=5)

terra documentation built on Oct. 11, 2021, 9:09 a.m.