I am trying to do some calculation on raster using following code
library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
r_n <- (r - global(r, fun = "min", na.rm=TRUE))/
(global(r, fun = "max", na.rm=TRUE) - global(r, fun = "min", na.rm=TRUE))
It throws the following error
Error in data.frame(value, row.names = rn, check.names = FALSE) : duplicate row.names: 374, 356, 348, 378,...
But if I do it using raster
R package, it runs fine like
library(raster)
r_raster <- stack(r)
r_n_raster <- (r_raster - minValue(r_raster))/
(maxValue(r_raster) - minValue(r_raster))
What should I do to make the code run with terra
package?