applyCats | R Documentation |
Applies a given set of "cats" (factor level ID-name pairs) to a factor raster. Any level names already shared between the given cats and the raster will be numerically remapped to the given cats IDs.
applyCats(raster, cats)
raster |
The factor |
cats |
A |
terra manages factor rasters by having each cell store an integer
ID (0, 1, 2, ...) which corresponds to a level name as found in
terra::cats()
. However, if you load a raster with levels "A", "B", "C"
and another raster with levels "B", "C", "D", terra won't detect the
overlapping levels since B=1 and C=2 in the first raster and B=0 and C=1 in
the second. This is important when it comes to creating prediction models
that take factor rasters as input. Let's say that level "C" is a
high-probability indicator of event X. If you generate a model with raster 1
the model will learn to associate X with the value C=2. If you then run the
model with raster 2, the model will predict high-probability of X at cells
with D=2, which is numerically correct but the level names don't match. The
setRasterLevels()
function solves this problem by ensuring that any
level names shared between two factor rasters will also share the same
integer ID.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.