r <- rast(system.file("ex/logo.tif", package="terra"))
set.seed(0)
r[[1]] <- flip(r[[1]], "horizontal")
r[[2]] <- flip(r[[2]], "vertical") + init(rast(r,1), runif)
r[[3]] <- init(rast(r,1), runif)
x <- focalPairs(r, w=5, "pearson", na.rm=TRUE)
plot(x)
# suppress warning "the standard deviation is zero"
suppressWarnings(x <- focalPairs(r, w=5, "pearson", use="complete.obs"))
z <- focalPairs(r, w=9, function(x, y) mean(x) + mean(y))
Run the code above in your browser using DataLab