Turns each element of a list-column into a row.

unnest_longer(
  .df,
  col,
  values_to = NULL,
  indices_to = NULL,
  indices_include = NULL,
  keep_empty = FALSE,
  names_repair = "check_unique",
  simplify = NULL,
  ptype = NULL,
  transform = NULL
)

Arguments

.df

A data.table or data.frame

col

Column to unnest

values_to

Name of column to store values

indices_to

Name of column to store indices

indices_include

Should an index column be included? Defaults to TRUE when col has inner names.

keep_empty

Return NA for any NULL elements of the list column

names_repair

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

simplify

Currently not supported. Errors if not NULL.

ptype

Optionally a named list of ptypes declaring the desired output type of each component.

transform

Optionally a named list of transformation functions applied to each component.

Examples

df <- tidytable(
  x = 1:3,
  y = list(0, 1:3, 4:5)
)

df %>% unnest_longer(y)
#> # A tidytable: 6 × 2
#>       x     y
#>   <int> <dbl>
#> 1     1     0
#> 2     2     1
#> 3     2     2
#> 4     2     3
#> 5     3     4
#> 6     3     5