knn {smerc} | R Documentation |
K nearest neighbors
Description
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.
Usage
knn(coords, longlat = FALSE, k = 1, d = NULL)
Arguments
coords |
An |
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 |
Value
An n \times k
matrix of nearest neighbors.
Examples
data(nydf)
coords <- nydf[, c("longitude", "latitude")]
knn(coords, longlat = TRUE, k = 4)
[Package smerc version 1.8.3 Index]