nearest_neighbors {rmi} | R Documentation |
Compute Nearest Neighbors
Description
Computes the nearest neighbor distances and indices of a sample using the infinite norm.
Usage
nearest_neighbors(data, k)
Arguments
data |
Matrix of sample observations, each row is an observation. |
k |
Neighborhood order. |
Details
Nearest neighbors are computed using the brute-force method.
Value
List of distances and indices of the k-nearest neighbors of each point in data
.
Examples
X <- cbind(1:10)
nearest_neighbors(X,3)
set.seed(123)
X <- cbind(runif(100),runif(100))
plot(X,pch=20)
points(X[3,1],X[3,2],col='blue',pch=19, cex=1.5)
nn <- nearest_neighbors(X,5)
a = X[nn$nn_inds[3,-1],1]
b = X[nn$nn_inds[3,-1],2]
points(a,b,col='red',pch=19, cex=1.5)
[Package rmi version 0.1.1 Index]