Description Usage Arguments Value See Also Examples
This function picks rows from a dataframe by matching n unique values from
the head (or tail) of a column. It is similar to dplyr::top_n(), but instead of
using min_rank() or max_rank(), it uses utils::head() or
utils::tail(); and var is flexible as in dplyr::pull().
1 |
.data |
A table of data. |
var |
A variable specified as:
The default returns the last column (on the assumption that is the column you have created most recently). This argument is taken by expression and supports quasiquotation (you can unquote column names and column positions). |
n |
Number of values used for matching, from the head (or tail) of
|
A filtered version of the input dataset.
dplyr::pull, dplyr::top_n, utils::head(), utils::tail().
Other general functions to pick or drop rows of a dataframe: in_top,
pick_recensus
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | df <- data.frame(x = 1:9, y = letters[1:3], stringsAsFactors = FALSE)
# `var` can be bare or quoted
(result <- pick_top(df, "y"))
identical(pick_top(df, y), result)
# matching `var` by position starting from the left
identical(pick_top(df, var = y), pick_top(df, var = 2))
# matching `var` by position starting from the right
identical(pick_top(df, var = y), pick_top(df, var = -1))
pick_top(df, y, n = 2)
# Negative values select from the tail
pick_top(df, y, n = -2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.