1\name{freq}
2
3\docType{methods}
4
5\alias{freq}
6\alias{freq,SpatRaster-method}
7
8\title{Frequency table}
9
10\description{
11Frequency table of the values of a SpatRaster. \code{NA}s are not counted unless \code{value=NA}.
12}
13
14\usage{
15\S4method{freq}{SpatRaster}(x, digits=0, value=NULL, bylayer=TRUE, usenames=FALSE)
16}
17
18\arguments{
19  \item{x}{SpatRaster}
20  \item{digits}{integer. Used for rounding the values before tabulation. Ignored if \code{NA}}
21  \item{value}{numeric. An optional single value to only count the number of cells with that value. This value can be \code{NA}}
22  \item{bylayer}{logical. If \code{TRUE} tabulation is done by layer}
23  \item{usenames}{logical. If \code{TRUE} layers are identified by their names instead of their numbers. Only relevant if \code{bylayer} is \code{TRUE}}
24}
25
26\value{
27\code{matrix} or \code{data.frame} with 3 columns (layer, value, count) or, if \code{bylayer=FALSE} two columns (value, count). If any of the layers of \code{x} is categorical, there is an additional column (label).
28A \code{data.frame} is returned if \code{usenames=TRUE} or if any of the layers of \code{x} is categorical.
29}
30
31
32\examples{
33r <- rast(nrows=10, ncols=10)
34set.seed(2)
35values(r) <- sample(5, ncell(r), replace=TRUE)
36
37freq(r)
38
39x <- c(r, r/3)
40freq(x, bylayer=FALSE)
41freq(x)
42
43freq(x, digits=1)
44freq(x, digits=-1)
45
46freq(x, value=5)
47
48}
49
50\keyword{spatial}
51\keyword{univar}
52