freq,GRaster-method | R Documentation |
freq()
tabulates the frequency of cell values in a raster. For rasters where datatype()
is integer
or factor
, the frequency of each value or level is reported. For other rasters, the range of values is divided into bins, and the number of cells with values in each bin is reported.
## S4 method for signature 'GRaster'
freq(x, digits = 3, bins = 100, value = NULL)
x |
A |
digits |
Numeric integer: Number of digits by which to round raster values. Ignored for integer and categorical rasters. |
bins |
Positive numeric integer: Number of bins in which to divide values of |
value |
Numeric or |
A data.frame
or a named list
of data.frame
s, one per layer in x
.
terra::freq()
, module r.stats
in GRASS
if (grassStarted()) {
# Setup
library(terra)
# Example data
madElev <- fastData("madElev") # raster
madCover <- fastData("madCover") # categorical raster
# Convert to GRasters
elev <- fast(madElev) # raster
cover <- fast(madCover) # categorical raster
# Frequencies of integer raster values
f <- freq(elev)
print(f) # have to do this sometimes if output is a data table
# Frequencies of categorical raster values
f <- freq(cover)
print(f) # have to do this sometimes if output is a data table
# Frequencies of given values
f <- freq(elev, value = 1)
print(f) # have to do this sometimes if output is a data table
# When a GRaster has non-integer values, they will be binned:
f <- freq(elev + 0.1, bins = 10)
print(f)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.