R/kdtools.R
Sort multidimensional data
kd_sort(x, ...) kd_is_sorted(x)
x | a matrix or arrayvec object |
---|---|
... | other arguments |
The algorithm used is a divide-and-conquer quicksort variant that recursively partions an range of tuples using the median of each successive dimension. Ties are resolved by cycling over successive dimensions. The result is an ordering of tuples matching their order if they were inserted into a kd-tree.
The matrix version will be slower because of data structure conversions.
x = kd_sort(matrix(runif(200), 100)) kd_is_sorted(x)#> [1] TRUEplot(x, type = "o", pch = 19, col = "steelblue", asp = 1)