# make a grid
g <- sf::st_make_grid(
cellsize = c(10, 10),
offset = c(0, 0),
n = c(2, 2)
)
# create neighbors
nb <- st_contiguity(g)
# cast to matrix
nb_as_matrix(nb)
# create weights
wt <- st_weights(nb)
# cast as matrix
wt_as_matrix(nb, wt)
Run the code above in your browser using DataLab