unnest: Unnest list-columns

View source: R/unnest.R

unnestR Documentation

Unnest list-columns

Description

Unnest list-columns.

Usage

unnest(
  .df,
  ...,
  keep_empty = FALSE,
  .drop = TRUE,
  names_sep = NULL,
  names_repair = "unique"
)

Arguments

.df

A data.table

...

Columns to unnest If empty, unnests all list columns. tidyselect compatible.

keep_empty

Return NA for any NULL elements of the list column

.drop

Should list columns that were not unnested be dropped

names_sep

If NULL, the default, the inner column names will become the new outer column names.

If a string, the name of the outer column will be appended to the beginning of the inner column names, with names_sep used as a separator.

names_repair

Treatment of duplicate names. See ?vctrs::vec_as_names for options/details.

Examples

df1 <- tidytable(x = 1:3, y = 1:3)
df2 <- tidytable(x = 1:2, y = 1:2)
nested_df <-
  data.table(
    a = c("a", "b"),
    frame_list = list(df1, df2),
    vec_list = list(4:6, 7:8)
  )

nested_df %>%
  unnest(frame_list)

nested_df %>%
  unnest(frame_list, names_sep = "_")

nested_df %>%
  unnest(frame_list, vec_list)

tidytable documentation built on Sept. 11, 2024, 8:05 p.m.