Aggregate point-wise distances over k nearest neighbors

aggregate_knn(data, fun, k)

Arguments

data

A numeric matrix, data frame or distance matrix

fun

A function to aggregate point-wise distances

k

An integer specifying number of nearest neighbors used to compute aggregation

Value

A numeric vector

Examples

aggregate_knn(iris[, -5], mean, 3) # average 3-nn
#> Warning: Data not a distance matrix. Euclidean distance matrix computed by default.
#> 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 "%>%"
aggregate_knn(dist(iris[, -5]), max, 5) # equivalent to exact 5-nn
#> 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 "%>%"