Return point-wise k nearest neighbor

nearest_neighbors(distance_matrix, k)

Arguments

distance_matrix

A distance matrix

k

An integer or sequence of integers specifying the desired nearest neighbors

Value

An N x k tibble with ordered pairwise distances

Details

A distance matrix (either a full square matrix or a "dist" object) is required as input.

Examples

my_dist <- dist(scale(state.x77)) nearest_neighbors(distance_matrix = my_dist, k = 1:3)
#> Error in tibble(N1 = as.numeric(as.factor(rownames(dmat)[col(dmat)])), N2 = as.numeric(as.factor(colnames(dmat)[row(dmat)])), distance = c(dmat)) %>% filter(N1 != N2): could not find function "%>%"