View source: R/weights-contiguity.R
| st_weights | R Documentation |
Calculate polygon spatial weights from a nb list. See spdep::nb2listw() for further details.
st_weights(nb, style = "W", allow_zero = NULL, ...)
nb |
A neighbor list object as created by |
style |
Default |
allow_zero |
If |
... |
additional arguments passed to |
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.
a list where each element is a numeric vector
Other weights:
st_inverse_distance(),
st_kernel_weights(),
st_nb_dists()
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]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.