I'm working on some post processing of a very large raster (437760000 cells) using other raster layers of the same extent/crs for constraints. The code is working for the most part but I'm running into an issue.
r1[r2== 6 & r3>= 40 & r3<= 60] <- sample(2:4, length(r1[r2== 6 & r3>= 40 & r3 <= 60]), replace = T)
Where r1, r2, and r3 are unique raster layers. r1 is being updated based on the constraints with the aim to improve the map.
This code executes with no issues but throws the following warning upon completion:
Warning message:
In .local(x, i, j = j, ..., value) :
the first replacement value is used for all cells
I want to ensure that all three values are being picked at random (and eventually I want to use the prob argument in sample to weight one of the values). I've tried numerous fixes and they all throw the same warning message, which I'm taking to mean that only one of the three values is being applied across the raster. I am working in terra for this.
Any thoughts? Thanks!