cur_group_id.: Context functions

cur_group_id.R Documentation

Context functions

Description

These functions give information about the "current" group.

  • cur_data() gives the current data for the current group

  • cur_column() gives the name of the current column (for use in across() only)

  • cur_group_id() gives a group identification number

  • cur_group_rows() gives the row indices for each group

Can be used inside summarize(), mutate(), & filter()

Usage

cur_group_id.()

Examples

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

df %>%
  mutate(
    across(c(x, y), ~ paste(cur_column(), .x))
  )

df %>%
  summarize(data = list(cur_data()),
            .by = y)

df %>%
  mutate(group_id = cur_group_id(),
         .by = y)

df %>%
  mutate(group_rows = cur_group_rows(),
         .by = y)

mtfairbanks/gdt documentation built on Nov. 24, 2022, 9:13 a.m.