| which_top_n {statnet.common} | R Documentation |
Top or bottom n elements of a vector
Description
Return the indices of the top or bottom abs(n) elements of a
vector, with several methods for resolving ties.
Usage
which_top_n(x, n, tied = c("given", "all", "none"))
Arguments
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 |
Value
An integer vector of indices on x, with an attribute
attr(, "tied") with the indicies of the tied elements (possibly
empty).
Examples
(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)))
[Package statnet.common version 4.13.0 Index]