Description Usage Arguments Value Note See Also Examples
Local functions for two RasterLayer objects (using a focal neighborhood)
| 1 2 | 
| x | RasterLayer or RasterStack/RasterBrick | 
| y | object of the same class as  | 
| ngb | integer. rectangular neighbourhood size. Either a single integer or a vector of two integers c(rows, cols), such as c(3,3) to have a 3 x 3 focal window | 
| fun | function | 
| filename | character. Output filename (optional) | 
| ... | additional arguments as for  | 
RasterLayer
The first two arguments that fun needs to accept are vectors representing the local cells of RasterLayer x and y (each of length ngb * ngb). It also must have an ellipsis (...) argument
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | set.seed(0)
b <- stack(system.file("external/rlogo.grd", package="raster"))
x <- flip(b[[2]], 'y') + runif(ncell(b))
y <- b[[1]] + runif(ncell(b))
f <- localFun(x, y, fun=cor)
## Not run: 
# local regression:
rfun <- function(x, y, ...) {
	m <- lm(y~x)
	# return R^2
	summary(m)$r.squared
}
ff <- localFun(x, y, fun=rfun)
plot(f, ff)
## End(Not run)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.