Returns a sort order after sorting by a vector within another vector.

custom_sort(..., decreasing = FALSE, unique = FALSE)

Arguments

...

Sequence of atomic vectors. Passed to order.

decreasing

Sort order. Passed to order.

unique

If FALSE (default), ties get the same rank. If TRUE, ties are broken.

Value

numeric sort order.

Examples


a <- c(1, 1, 1, 2, 2)
b <- c(2, 3, 2, 1, 1)

custom_sort(a, b)
#> [1] 1 2 1 3 3
custom_sort(b, a)
#> [1] 2 3 2 1 1
custom_sort(b, a, unique = TRUE)
#> [1] 3 5 4 1 2