st_weights {sfdep} | R Documentation |
Calculate spatial weights
Description
Calculate polygon spatial weights from a nb
list. See spdep::nb2listw()
for further details.
Usage
st_weights(nb, style = "W", allow_zero = NULL, ...)
Arguments
nb |
A neighbor list object as created by |
style |
Default |
allow_zero |
If |
... |
additional arguments passed to |
Details
Under the hood, st_weights()
creates a listw
object and then extracts the weights elements from it as the neighbours
element is already–presumably–already existent in the neighbors list you've already created. listw
objects are recreated using recreate_listw()
when calculating other statistics.
Value
a list where each element is a numeric vector
See Also
Other weights:
st_inverse_distance()
,
st_kernel_weights()
,
st_nb_dists()
Examples
if (requireNamespace("dplyr", quietly = TRUE)) {
library(magrittr)
guerry %>%
dplyr::mutate(nb = st_contiguity(geometry),
wt = st_weights(nb),
.before = 1)
}
# using geometry column directly
nb <- st_contiguity(guerry$geometry)
wt <- st_weights(nb)
wt[1:3]