slice-max

Keep the n rows with the largest value of col.

NoteExperimental

This function is experimental; its interface may change without notice.

Since 0.6.0.

Numeric ordering: cell values are parsed as numbers. Rows whose col is non-numeric or missing sort last, so they are kept only when n exceeds the numeric rows. by: ranks within each group (none for the whole dataset). Up to n rows are kept per group, ties keeping input order (no tie expansion).

Usage

slice-max(
  data,
  col,
  n: 1,
  by: none,
)

Parameters

Parameter Default Description
data Row-store (array of dicts) or column-store (dict of arrays).
col Column to rank by.
n 1 Number of rows to keep per group.
by none Grouping columns: none, a column name, or an array of names.

Returns

A row-store array of the top rows.

Examples

The thirstiest car in each class.

#let worst = slice-max(mpg, "hwy", by: "class")

See also

slice-min.

Back to top