topn: Select top (or bottom) n rows (by value)

Description Usage Arguments Value See Also Examples

Description

Analogous function for top_n and top_frac in dplyr, but with a different API.

Usage

1
2
3
top_n_dt(data, n, wt = NULL)

top_frac_dt(data, n, wt = NULL)

Arguments

data

data.frame

n

If n is positive, selects the top rows. If negative, selects the bottom rows.

wt

(Optional). The variable to use for ordering. If not specified, defaults to the last variable in the data.frame.

Value

data.table

See Also

top_n

Examples

1
2
3
4
iris %>% top_n_dt(10,Sepal.Length)
iris %>% top_n_dt(-10,Sepal.Length)
iris %>% top_frac_dt(.1,Sepal.Length)
iris %>% top_frac_dt(-.1,Sepal.Length)

hope-data-science/tidydt documentation built on Feb. 21, 2020, 10:25 a.m.