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.