pick_top: Pick dataframe rows by matching n values from the head (or...

Description Usage Arguments Value See Also Examples

Description

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().

Usage

1
pick_top(.data, var, n = 1)

Arguments

.data

A table of data.

var

A variable specified as:

  • a literal variable name

  • a positive integer, giving the position counting from the left

  • a negative integer, giving the position counting from the right.

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 var.

Value

A filtered version of the input dataset.

See Also

dplyr::pull, dplyr::top_n, utils::head(), utils::tail().

Other general functions to pick or drop rows of a dataframe: in_top, pick_recensus

Examples

 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)

forestgeo/fgeo.misc documentation built on June 23, 2019, 6:26 p.m.