knn {smerc} | R Documentation |
knn
returns the k nearest neighbors of the
n coordinates in coords
. The nearest neighbors
are constructed to be self-inclusive, i.e., an
observations is its closest neighbor.
knn(coords, longlat = FALSE, k = 1, d = NULL)
coords |
An n \times 2 matrix of centroid coordinates for the regions. |
longlat |
The default is |
k |
An integer indicating the maximum number of regions to inclue in a potential cluster. Default is 10 |
d |
An n by n distance matrix. If provided,
this is used instead of computing |
An n \times k matrix of nearest neighbors.
data(nydf) coords = nydf[,c("longitude", "latitude")] knn(coords, longlat = TRUE, k = 4)