Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

unnest..html

Unnest a nested data.table


Description

Unnest a nested data.table.

Usage

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

Arguments

.df

A nested data.table

...

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

.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

nested_df <-
  data.table(
    a = 1:10,
    b = 11:20,
    c = c(rep("a", 6), rep("b", 4)),
    d = c(rep("a", 4), rep("b", 6))
  ) %>%
  nest_by.(c, d) %>%
  mutate.(pulled_vec = map.(data, ~ pull.(.x, a)))

nested_df %>%
  unnest.(data)

nested_df %>%
  unnest.(data, names_sep = "_")

nested_df %>%
  unnest.(data, pulled_vec)

tidytable

Tidy Interface to 'data.table'

v0.6.1
MIT + file LICENSE
Authors
Mark Fairbanks [aut, cre], Abdessabour Moutik [ctb], Matt Carlson [ctb], Ivan Leung [ctb], Ross Kennedy [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.