fun_kLargest: Find the 'k'-largest/smallest values (and apply a function to...

View source: R/miscellaneous_functions.R

fun_kLargestR Documentation

Find the k-largest/smallest values (and apply a function to these values)

Description

Find the k-largest/smallest values (and apply a function to these values)

Usage

fun_kLargest(x, largest = TRUE, fun = NULL, k = 10L, na.rm = FALSE, ...)

Arguments

x

A numeric vector

largest

A logical value. See return value.

fun

A function which requires one argument or "index". fun will be applied to the k-largest/smallest values of x.

k

An integer value. The k-largest/smallest value(s) of x will be used. The largest/smallest value will be used if 0 or negative.

na.rm

A logical value indicating whether NA values should be stripped before the computation proceeds.

...

Optional arguments to be passed to fun

Value

A vector of length k,

  • if is.null(fun), then a vector with the k-largest (if largest = TRUE) or k-smallest (if largest = FALSE) values of x;

  • if fun = "index", then a vector with indices of the k-largest/smallest values (NOTE: this is truncated to the k-first indices!).

Otherwise, the result of applying fun to the k-largest/smallest values.


DrylandEcology/rSW2utils documentation built on Dec. 9, 2023, 10:44 p.m.