View source: R/synchroniseNA.R
synchroniseNA | R Documentation |
This function ensures that cells containing NAs are the same among all the layers of a raster stack, i.e.that for any given pixel of the stack, if one layer has a NA, then all layers should be set to NA for that pixel.
synchroniseNA(x)
x |
a raster stack object which needs to be synchronised. |
This function can do that in two different ways; if your computer has enough RAM a fast way will be used; otherwise a slower but memory-safe way will be used.
Boris Leroy leroy.boris@gmail.com
with help from C. N. Meynard, C. Bellard & F. Courchamp
# Creation of a stack with different NAs across layers
m <- matrix(nr = 10, nc = 10, 1:100)
r1 <- rast(m)
r2 <- rast(m)
r1[sample(1:ncell(r1), 20)] <- NA
r2[sample(1:ncell(r2), 20)] <- NA
s <- c(r1, r2)
# Effect of the synchroniseNA() function
plot(s) # Not yet synchronised
s <- synchroniseNA(s)
plot(s) # Synchronised
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.