max_n: Select vector elements by sorted position

View source: R/utils.R

max_nR Documentation

Select vector elements by sorted position

Description

Returns elements of x by position n after sorting by, decreasing for max_n() or increasing for min_n(). Any NA elements of x are ranked last for either function.

Usage

max_n(x, n = 2L)

min_n(x, n = 2L)

Arguments

x

A vector.

n

Numeric vector giving the ranks of elements to be returned.

Value

A vector of length equal to n.

Examples

x <- 5:8
max_n(x, 2)
min_n(x, 1:2)
max_n(c(5:7, NA), 1:4)
min_n(c(5:7, NA), 1:4)

jedwards24/edwards documentation built on Sept. 2, 2023, 8:16 a.m.