Unnest a list-column of vectors into a wide data frame

unnest_wider.(
  .df,
  col,
  names_sep = NULL,
  simplify = NULL,
  names_repair = "check_unique",
  ptype = NULL,
  transform = NULL
)

Arguments

.df

A data.table or data.frame

col

Column to unnest

names_sep

If NULL, the default, the names will be left as they are. If a string, the inner and outer names will be pasted together with names_sep as the separator.

simplify

Currently not supported. Errors if not NULL.

names_repair

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

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)
)

# Automatically creates names
df %>% unnest_wider(y)
#> New names:
#>  `1` -> `...1`
#>  `2` -> `...2`
#>  `3` -> `...3`
#> # A tidytable: 3 × 4
#>       x  ...1  ...2  ...3
#>   <int> <dbl> <int> <int>
#> 1     1     0    NA    NA
#> 2     2     1     2     3
#> 3     3     4     5    NA

# But you can provide names_sep for increased naming control
df %>% unnest_wider(y, names_sep = "_")
#> # A tidytable: 3 × 4
#>       x   y_1   y_2   y_3
#>   <int> <dbl> <int> <int>
#> 1     1     0    NA    NA
#> 2     2     1     2     3
#> 3     3     4     5    NA