st_lag: Calculate spatial lag

View source: R/lag.R

st_lagR Documentation

Calculate spatial lag

Description

Calculates the spatial lag of a numeric variable given a neighbor and weights list.

Usage

st_lag(x, nb, wt, na_ok = FALSE, allow_zero = NULL, ...)

Arguments

x

A numeric vector

nb

A neighbor list object as created by st_neighbors().

wt

A weights list as created by st_weights().

na_ok

Default FALSE. If, TRUE missing values return a lagged NA.

allow_zero

If TRUE, assigns zero as lagged value to zone without neighbors.

...

See ?spdep::lag.listw for more.

Value

a numeric vector with same length as x

See Also

Other stats: local_moran()

Examples

geo <- sf::st_geometry(guerry)
nb <- st_contiguity(geo)
wt <- st_weights(nb)

st_lag(guerry$crime_pers, nb, wt)

sfdep documentation built on Sept. 13, 2024, 5:07 p.m.