Learn R Programming

tidytable (version 0.10.2)

slice.: Choose rows in a data.table

Description

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

Usage

slice.(.df, ..., .by = NULL)

Arguments

.df

A data.frame or data.table

...

Integer row values

.by

Columns to group by

Examples

Run this code
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)

Run the code above in your browser using DataLab