Sort multidimensional data

kd_sort(x, ...)

kd_is_sorted(x)

Arguments

x

a matrix or arrayvec object

...

other arguments

Details

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.

Note

The matrix version will be slower because of data structure conversions.

See also

arrayvec

Examples

x = kd_sort(matrix(runif(200), 100)) kd_is_sorted(x)
#> [1] TRUE
plot(x, type = "o", pch = 19, col = "steelblue", asp = 1)