Return point-wise k nearest neighbor
nearest_neighbors(distance_matrix, k)
distance_matrix | A distance matrix |
---|---|
k | An integer or sequence of integers specifying the desired nearest neighbors |
An N x k tibble with ordered pairwise distances
A distance matrix (either a full square matrix or a "dist" object) is required as input.
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 "%>%"