set.seed(0)
r <- rast(nrows=10, ncols=10, nlyrs=3)
values(r) <- runif(ncell(r) * nlyr(r))
x <- mean(r)
# note how this returns one layer
x <- sum(c(r, r[[2]]), 5)
# and this returns three layers
y <- sum(r, r[[2]], 5)
max(r)
## when adding a number, do you want 1 layer or all layers?
# 1 layer
max(r, 0.5)
# all layers
max(r, 0.5, par=TRUE)
y <- stdev(r)
# not the same as
yy <- app(r, sd)
z <- stdev(r, r*2)
x <- mean(r, filename=paste0(tempfile(), ".tif"))
v <- values(r)
set.seed(3)
v[sample(length(v), 50)] <- NA
values(r) <- v
is.na(r)
anyNA(r)
allNA(r)
countNA(r)
countNA(r, 2)
Run the code above in your browser using DataLab