Find nearest neighbors

kd_nearest_neighbors(x, v, n)

kd_nn_indices(x, v, n)

kd_nearest_neighbor(x, v)

Arguments

x

an object sorted by kd_sort

v

a vector specifying where to look

n

the number of neighbors to return

Examples

x = matrix(runif(200), 100) y = matrix_to_tuples(x) kd_sort(y, inplace = TRUE)
#> [,1] [,2] #> [1,] 0.01327260 0.04300129 #> [2,] 0.09462277 0.17903429 #> [3,] 0.01952525 0.27264620 #> [4,] 0.19900078 0.17322484 #> [5,] 0.21833843 0.13334855 #> (continues for 95 more rows)
y[kd_nearest_neighbor(y, c(1/2, 1/2)),]
#> [1] 0.5234284 0.4968253
kd_nearest_neighbors(y, c(1/2, 1/2), 3)
#> [,1] [,2] #> [1,] 0.5494615 0.5447052 #> [2,] 0.5160349 0.4530892 #> [3,] 0.5234284 0.4968253
y[kd_nn_indices(y, c(1/2, 1/2), 5),]
#> [,1] [,2] #> [1,] 0.3673290 0.5242801 #> [2,] 0.3915421 0.5144025 #> [3,] 0.5494615 0.5447052 #> [4,] 0.5160349 0.4530892 #> [5,] 0.5234284 0.4968253