Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

localFun

Local functions


Description

Local functions for two RasterLayer objects (using a focal neighborhood)

Usage

## S4 method for signature 'RasterLayer,RasterLayer'
localFun(x, y, ngb=5, fun, filename='', ...)

Arguments

x

RasterLayer or RasterStack/RasterBrick

y

object of the same class as x, and with the same number of layers

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 writeRaster

Value

RasterLayer

Note

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

See Also

Examples

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)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.