Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

top_n..html

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


Description

Select the top or bottom entries in each group, ordered by wt.

Usage

top_n.(.df, n = 5, wt = NULL, .by = NULL)

Arguments

.df

A data.frame or data.table

n

Number of rows to return

wt

Optional. The variable to use for ordering. If NULL uses the last column in the data.table.

.by

Columns to group by

Examples

test_df <- data.table(
  x = 1:5,
  y = 6:10,
  z = c(rep("a", 3), rep("b", 2))
)

test_df %>%
  top_n.(2, wt = y)

test_df %>%
  top_n.(2, wt = y, .by = z)

tidytable

Tidy Interface to 'data.table'

v0.6.1
MIT + file LICENSE
Authors
Mark Fairbanks [aut, cre], Abdessabour Moutik [ctb], Matt Carlson [ctb], Ivan Leung [ctb], Ross Kennedy [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.