Learn R Programming

tidyfst (version 0.7.7)

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

Description

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

Usage

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

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataLab