Description Usage Arguments Value Examples
Find nearest neighbors
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | kd_nearest_neighbors(x, v, n, ...)
## S3 method for class 'matrix'
kd_nearest_neighbors(x, v, n, cols = NULL, alpha = 0, ...)
## S3 method for class 'arrayvec'
kd_nearest_neighbors(x, v, n, ...)
## S3 method for class 'data.frame'
kd_nearest_neighbors(x, v, n, cols = NULL, w = NULL, ...)
kd_nn_indices(x, v, n, ...)
## S3 method for class 'arrayvec'
kd_nn_indices(x, v, n, distances = FALSE, ...)
## S3 method for class 'matrix'
kd_nn_indices(x, v, n, cols = NULL, distances = FALSE, alpha = 0, ...)
## S3 method for class 'data.frame'
kd_nn_indices(x, v, n, cols = NULL, w = NULL, distances = FALSE, ...)
kd_nearest_neighbor(x, v)
## S3 method for class 'matrix'
kd_nearest_neighbor(x, v)
## S3 method for class 'arrayvec'
kd_nearest_neighbor(x, v)
|
x |
an object sorted by |
v |
a vector specifying where to look |
n |
the number of neighbors to return |
... |
ignored |
cols |
integer or character vector or formula indicating columns |
alpha |
approximate neighbors within (1 + alpha) |
w |
distance weights |
distances |
return distances as attribute if true |
kd_nearest_neighbors | one or more rows from the sorted input |
kd_nn_indices | a vector of row indices indicating the result |
kd_nearest_neighbor | the row index of the neighbor |
1 2 3 4 5 6 7 8 | if (has_cxx17()) {
x = matrix(runif(200), 100)
y = matrix_to_tuples(x)
kd_sort(y, inplace = TRUE)
y[kd_nearest_neighbor(y, c(1/2, 1/2)),]
kd_nearest_neighbors(y, c(1/2, 1/2), 3)
y[kd_nn_indices(y, c(1/2, 1/2), 5),]
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.