slice_min.: Choose rows in a data.table

View source: R/slice-min-max.R

slice_min.R Documentation

Choose rows in a data.table

Description

Choose rows in a data.table. Grouped data.tables grab rows within each group.

Usage

slice_min.(.df, order_by, n = 1, ..., with_ties = TRUE, .by = NULL, by = NULL)

Arguments

.df

A data.frame or data.table

order_by

Variable to arrange by

n

Number of rows to grab

...

Integer row values

with_ties

Should ties be kept together. The default TRUE may return can return multiple rows if they are equal. Use FALSE to ignore ties.

.by, by

Columns to group by

Examples

df <- data.table(
  x = 1:4,
  y = 5:8,
  z = c("a", "a", "a", "b")
)

df %>%
  slice(1:3)

df %>%
  slice(1, 3)

df %>%
  slice(1:2, .by = z)

df %>%
  slice_head(1, .by = z)

df %>%
  slice_tail(1, .by = z)

df %>%
  slice_max(order_by = x, .by = z)

df %>%
  slice_min(order_by = y, .by = z)

tidytable documentation built on Oct. 5, 2023, 5:07 p.m.