partial_sort | R Documentation |
Partial sort an lvec
partial_sort(x, pivots, clone = TRUE) partial_order(x, pivots)
x |
an object of type |
pivots |
a numeric vector with indices at which the vector will be sorted. See details for more information. |
clone |
clone the vector first before sorting; or sort (and therefore modify) the input vector directly. |
After partial sorting the vector values at the pivots are the same as the
vector values of a completely sorted vector. Furthermore, for each pivot
i
all elements x[j]; j < i
are smaller or equal to than
x[i]
and all elements x[j]; j > i
are larger than or equal to
x[i]
.
The speed of this operation should be O(n, k) with n the size of the
lvec
and k the number of pivots.
x <- as_lvec(rnorm(100)) y <- partial_sort(x, c(10, 50, 90)) x_sorted <- sort(x) stopifnot(all(y[c(10, 50, 90)] == x_sorted[c(10, 50, 90)])) stopifnot(max(y[1:9]) <= min(y[11:100])) stopifnot(max(y[1:49]) <= min(y[51:100])) stopifnot(max(y[1:89]) <= min(y[91:100]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.