extrema_by {table.express} | R Documentation |
Find rows with extrema in specific columns
Description
Find rows with maxima/minima in given columns.
Usage
max_by(.data, .col, ...)
## S3 method for class 'ExprBuilder'
max_by(
.data,
.col,
...,
.some = FALSE,
.chain = getOption("table.express.chain", TRUE)
)
## S3 method for class 'data.table'
max_by(.data, .col, ..., .expr = FALSE)
min_by(.data, .col, ...)
## S3 method for class 'ExprBuilder'
min_by(
.data,
.col,
...,
.some = FALSE,
.chain = getOption("table.express.chain", TRUE)
)
## S3 method for class 'data.table'
min_by(.data, .col, ..., .expr = FALSE)
Arguments
.data |
An instance of ExprBuilder. |
.col |
A character vector indicating the columns that will be searched for extrema. |
... |
Optionally, columns to group by, either as characters or symbols. |
.some |
If |
.chain |
Logical. Should a new frame be automatically chained to the expression if the clause being set already exists? |
.expr |
If the input is a |
Details
These verbs implement the idiom shown here by
leveraging nest_expr()
. The whole nested expression is assigned to i
in the data.table
's
frame. It is probably a good idea to use this on a frame that has no other frames preceding it
in the current expression, given that nest_expr()
uses the captured data.table
, so consider
using chain()
when needed.
Several columns can be specified in .col
, and depending on the value of .some
, the rows with
all or some extrema are returned, using &
or |
respectively. Depending on your data, using
more than one column might not make sense, resulting in an empty data.table
.
Examples
data("mtcars")
data.table::as.data.table(mtcars) %>%
max_by("mpg", "vs")