I would like to replace raster values only in specific zone of the raster. Say this is my example raster:
library(raster)
r <- raster(ncol=1000, nrow=1000)
r[] <- runif(ncell(r),0,1)
extent(r) <- matrix(c(0, 0, 1000, 1000), nrow=2)
What I would like to do now, is to change all values that equal to val <- 0.8
and replace with valnew <- 0.2
.
The extent of raster where my function should search and replace values is following (only this square of raster should be searched for val
values in raster and replaced with newval
)
extentnewvals <- matrix(c(300, 300, 500, 500), nrow=2)
Any ideas how to approach it?