# create raster with categorical values
x <- terra::rast(matrix(c(1, 2, 4, 0, NA, 1), nrow = 3))
# plot the raster
if (FALSE) {
plot(x, main = "x")
}
# convert to binary stack
y <- binary_stack(x)
# plot result
if (FALSE) {
plot(y)
}
Run the code above in your browser using DataLab