3

Having 10 raster files in one directory and another 10 rasters in another directory and both have the same dimensions.

directory 1:

    files1 <- list.files("C:\\2010", "*.envi", full.names = TRUE)
    s <- stack(files1)

directory 2:

 files2 <- list.files("C:\\2012", "*.envi", full.names = TRUE)
 s1 <- stack(files2)

I would like to filter s based on s1. I want to replace values in all layers in s by NA whenever corresponding layers in s1 have values greater than 0.6(corresponding pixels).

8

Something like:

s1[s2 > 0.6] <- NA

This is the standard R way of doing things like this. You use s2 to make a subset in s1, and then you replace that subset by NA. You might need to do some looping if rasterstacks do not support this directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.