I have a stack of 4 rasters. I need an average correlation between the time between a pixel and each of its 8 neighbors.
some data:
library(raster) r1=raster(matrix(runif(25),nrow=5)) r2=raster(matrix(runif(25),nrow=5)) r3=raster(matrix(runif(25),nrow=5)) r4=raster(matrix(runif(25),nrow=5)) s=stack(r1,r2,r3,r4)
so for a pixel at position x, which has 8 neighbors at positions NE, E, SE, S, etc., I want the average value
cor(x,NE) cor(x,E) cor(x,SE) cor(x,S) cor(x,SW) cor(x,W) cor(x,NW) cor(x,N)
and the average value stored at position x in the resulting raster. Loud cells will be NA or, if possible, a flag to calculate the average correlation only with the cells to which it touches (or 3 or 5 cells). Thanks!
source share