n_top: Return the Top n values of a data.frame

Description Usage Arguments Examples

View source: R/top_n.R

Description

This function returns the top n values of a data.frame or data.table based on user provided function and column

Usage

1
n_top(df, col, n, fun = function(x) {     -x }, keep_ordering = T)

Arguments

df

A data.table or data.frame

col

A character string of the column used to pick top values

n

The number of top values to keep, nrow(df) < n then nrow(df) is used

fun

The ordering function to apply to col. Default is function(x)-x which keeps largest.

keep_ordering

Logical, if TRUE then maintain original ordering, if FALSE order based on fun

Examples

1
2
n_top(df, col = 'v1', n = 5) returns a data.table with the 5 largest values of v1 in the original ordering
n_top(df, col = 'v1', n = 10, fun = function(x){-abs(x)}, keep_ordering = F) returns a data.table with 10 largest absolute values of v1, ordered by descending absolute values of v1

joshua-ruf/fidelis documentation built on July 20, 2019, 1:56 a.m.