top_n

0th

Percentile

Select top n rows (by value).

This is a convenient wrapper that uses filter and rank to select the top n entries in each group, ordered by wt.

Usage
top_n(x, n, wt = NULL)
Arguments
x
a tbl to filter
n
number of rows to return. If x is grouped, this is the number of rows per group. May include more than n if there are ties.
wt
the variable to use for ordering. If not specified, defaults to the last varible in the tbl.
Aliases
  • top_n
Examples
if (require("Lahman")) {
  players <- group_by(tbl_df(Batting), playerID)
  games <- tally(players, G)
  top_n(games, 10, n)

  # A little nicer with %.%
  tbl_df(Batting) %.% group_by(playerID) %.% tally(G) %.% top_n(10)
}
Documentation reproduced from package dplyr, version 0.1, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.