I wand to reclassify a raster with a for loop
based on seq
with reclassify function
from raster package
, the output of the following code is empty, I don't understand why.
#create a random raster
sam <- sample(seq(0,1,0.01), 1000*1000, replace = TRUE)
r1 <- raster(nrows = 1000, ncols = 1000, vals = sam)
#create the scale for reclassify
scale <- seq(0,1,0.2)
#the for loop
cl_r <- for (i in 1:length(scale)){
reclassify(r1, c(scale[i], scale[i+1], scale[i+1]))
}
The output:
> cl_r
NULL
I suppose that scale[i+1]
is understandable by R as scale[1+1]
works.