terra (version 0.3-7)

factors: Factors

Description

These functions allow for defining a SpatRaster layer as a categorical variable. The cell values are an index (id), whereas the actual values are stored seperately, in a table (sometimes called "Raster Attribute Table"). This table is a data.frame. The first column in the RAT ("ID") has the unique cell values of the layer; this column should normally not be changed. The other columns can be of any basic type (factor, character, integer, numeric or logical).

Function 'levels' returns the RAT for inspection. It can be modified and set using levels <- value.

as.factor and ratify create a layer with a RAT table. deratify creates a single layer for a (or each) variable in the RAT table.

Usage

is.factor(x)
as.factor(x)
levels(x)

Arguments

x

SpatRaster

Value

SpatRaster; list (levels); boolean (is.factor)

Examples

Run this code
# NOT RUN {
set.seed(0)
r <- rast(nrow=10, ncol=10)
values(r) <- runif(ncell(r)) * 10
is.factor(r)

r <- round(r)
f <- as.factor(r)
is.factor(f)
# }

Run the code above in your browser using DataLab