library(terra)
rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:1, 50)
rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,50))
rastList <- list(rast1, rast2)
result <- diversityStack(rasterList = rastList,
template = rast2)
result
plot(result)
Run the code above in your browser using DataLab