Find nearest neighbors

kd_nearest_neighbors(x, v, n, ...)

# S3 method for matrix
kd_nearest_neighbors(x, v, n, ...)

# S3 method for arrayvec
kd_nearest_neighbors(x, v, n, ...)

# S3 method for data.frame
kd_nearest_neighbors(x, v, n, cols = 1:ncol(x), w = rep(1, length(cols)), ...)

kd_nn_indices(x, v, n, ...)

# S3 method for matrix
kd_nn_indices(x, v, n, ...)

# S3 method for arrayvec
kd_nn_indices(x, v, n, ...)

# S3 method for data.frame
kd_nn_indices(x, v, n, cols = 1:ncol(x), w = rep(1, length(cols)), ...)

kd_nearest_neighbor(x, v)

# S3 method for matrix
kd_nearest_neighbor(x, v)

# S3 method for arrayvec
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

...

additional arguments

cols

integer indices of columns to use

w

distance weights

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.07588305 0.12110888 #> [3,] 0.04584931 0.35058816 #> [4,] 0.09462277 0.17903429 #> [5,] 0.10131376 0.11304750 #> (continues for 95 more rows)
y[kd_nearest_neighbor(y, c(1/2, 1/2)),]
#> [1] 0.4968253 0.5492207
kd_nearest_neighbors(y, c(1/2, 1/2), 3)
#> [,1] [,2] #> [1,] 0.3915421 0.5144025 #> [2,] 0.5494615 0.5447052 #> [3,] 0.4968253 0.5492207
y[kd_nn_indices(y, c(1/2, 1/2), 5),]
#> [,1] [,2] #> [1,] 0.6227988 0.4511203 #> [2,] 0.5948192 0.5787815 #> [3,] 0.3915421 0.5144025 #> [4,] 0.5494615 0.5447052 #> [5,] 0.4968253 0.5492207