View source: R/misc.utilities.R
| which_top_n | R Documentation |
n elements of a vectorReturn the indices of the top or bottom abs(n) elements of a
vector, with several methods for resolving ties.
which_top_n(x, n, tied = c("given", "all", "none"))
x |
a vector on which |
n |
the number of elements to attempt to select; if positive
top |
tied |
a string to specify how to handle multiple elements
tied for |
An integer vector of indices on x, with an attribute
attr(, "tied") with the indicies of the tied elements (possibly
empty).
(x <- rep(1:4, 1:4))
stopifnot(identical(which_top_n(x, 5, "all"), structure(4:10, tied = 4:6)))
stopifnot(identical(which_top_n(x, 5, "none"), structure(7:10, tied = 4:6)))
stopifnot(identical(which_top_n(x, 5), structure(6:10, tied = 4:6)))
stopifnot(identical(which_top_n(x, -5, "all"), structure(1:6, tied = 4:6)))
stopifnot(identical(which_top_n(x, -5, "none"), structure(1:3, tied = 4:6)))
stopifnot(identical(which_top_n(x, -5), structure(1:5, tied = 4:6)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.