getKminmax: Get the k largest/smallest elements

View source: R/getKminmax.R

getKminmaxR Documentation

Get the k largest/smallest elements

Description

Extract the k largest or smallest values and their indices for each column of a matrix.

Usage

getKminmax(x, k, flag = "max")

Arguments

x

a data matrix or data frame.

k

an integer specifying the number of extreme values. Must be <= nrows(x).

flag

use "min" or "max" (default) to select smallest or largest elements.

Details

Order the values of each column of x and determine the k smallest (flag = "min") or largest (flag = "max") values and their indices. NA's in the data are ignored.

Value

List with elements:

ik

indices of ordered extreme values

minmax

ordered extreme values.

Author(s)

Ariane Schad

References

Brombacher, E., Schad, A., Kreutz, C. (2020). Tail-Robust Quantile Normalization. BioRxiv.

Examples

# Create a data matrix
x <- matrix(c(5,2,3,NA,4,1,4,2,3,4,6,NA,1,3,1),ncol=3)
# Get indices of the 5 largest values in each column
getKminmax(x, k = 5, "max") 

arianeschad/mbqn documentation built on March 29, 2022, 6:56 p.m.