powered by
Create a k-nearest neighbors based spatial weights
knn_weights( sf_obj, k, power = 1, is_inverse = FALSE, is_arc = FALSE, is_mile = TRUE )
An instance of Weight-class
An sf (simple feature) object
a positive integer number for k-nearest neighbors
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication.
(optional) FALSE (default) or TRUE, apply inverse on distance value
(optional) FALSE (default) or TRUE, compute arc distance between two observations
(optional) TRUE (default) or FALSE, convert distance unit from mile to km.
library(sf) guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda") guerry <- st_read(guerry_path) knn6_w <- knn_weights(guerry, 6) summary(knn6_w)
Run the code above in your browser using DataLab