Learn R Programming

terra (version 1.8-86)

freq: Frequency table

Description

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

You can provide a SpatVector or additional SpatRaster to define zones for which to do tabulations.

Usage

# S4 method for SpatRaster
freq(x, digits=0, value=NULL, bylayer=TRUE, usenames=FALSE, 
		zones=NULL, wide=FALSE, touches=FALSE)

Arguments

Value

A data.frame with 3 columns (layer, value, count) unless bylayer=FALSE in which case adata.frame with two columns is returned (value, count).

Examples

Run this code
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)

Run the code above in your browser using DataLab