Learn R Programming

tidytable (version 0.11.1)

nest_by: Nest data.tables

Description

Nest data.tables by group.

Note: nest_by() does not return a rowwise tidytable.

Usage

nest_by(.df, ..., .key = "data", .keep = FALSE)

Arguments

.df

A data.frame or data.table

...

Columns to group by. If empty nests the entire data.table. tidyselect compatible.

.key

Name of the new column created by nesting.

.keep

Should the grouping columns be kept in the list column.

Examples

Run this code
df <- data.table(
  a = 1:5,
  b = 6:10,
  c = c(rep("a", 3), rep("b", 2)),
  d = c(rep("a", 3), rep("b", 2))
)

df %>%
  nest_by()

df %>%
  nest_by(c, d)

df %>%
  nest_by(where(is.character))

df %>%
  nest_by(c, d, .keep = TRUE)

Run the code above in your browser using DataLab