# create a binary raster stack
x <- terra::rast(list(
terra::rast(matrix(c(1, 0, 0, 1, NA, 0), nrow = 3)),
terra::rast(matrix(c(0, 1, 0, 0, NA, 0), nrow = 3)),
terra::rast(matrix(c(0, 0, 1, 0, NA, 1), nrow = 3))
))
# plot data
plot(x)
# convert to category layer
y <- category_layer(x)
# plot result
if (FALSE) {
plot(y)
}
Run the code above in your browser using DataLab