which.maxn: Where are the n largest or n smallest elements in a numeric...

View source: R/which_maxn.R

which.maxnR Documentation

Where are the n largest or n smallest elements in a numeric vector ?

Description

Determines the locations, i.e., indices of the n largest or n smallest elements of a numeric vector.

Usage

which.maxn(x, n = 1)

Arguments

x

numeric vector

n

integer >= 1

Value

A vector of length at most n with the indices of the n largest / smaller elements. NAs are discarded and that can cause the vector to be smaller than n.

Author(s)

Søren Højsgaard, sorenh@math.aau.dk

See Also

which.max, which.min

Examples


x <- c(1:4, 0:5, 11, NA, NA)
ii <- which.minn(x, 5)

x <- c(1, rep(NA,10), 2)
ii <- which.minn(x, 5)


hojsgaard/doBy documentation built on April 19, 2024, 12:05 a.m.