I am working in R with terra library. I have a SpatRaster of 21 layers with values 0 and 1.
This is my SpatRaster object
mascara1_t
class : SpatRaster
dimensions : 628, 865, 21 (nrow, ncol, nlyr)
resolution : 0.0001796631, 0.0001796631 (x, y)
extent : -0.5923491, -0.4369406, 39.93461, 40.04743 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source(s) : memory
names : lyr1, lyr2, lyr3, lyr4, lyr5, lyr6, …
min values : 0, 0, 0, 0, 0, 0, …
max values : 1, 1, 1, 1, 1, 1, …
I want to create a new SpatRaster object meeting this criteria. The first time a pixel is 0, then, the value change to 0 in the following bands. Lets say for instance a pixel has values of 1 and then for the fifth band the value changed to 0. Then I would like to have value 0 for the rest of bands. How can I do this in R? This is my code so far. Thanks in advance!
Jess is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.