partial_sort: Partial sort an lvec

Description Usage Arguments Details Examples

View source: R/partial_sort.R

Description

Partial sort an lvec

Usage

1
2
3
partial_sort(x, pivots, clone = TRUE)

partial_order(x, pivots)

Arguments

x

an object of type lvec

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.

Details

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.

Examples

1
2
3
4
5
6
7
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]))

ldat documentation built on March 26, 2020, 7:59 p.m.

Related to partial_sort in ldat...