Separates a single column into multiple columns

separate_wider_delim(
  .df,
  cols,
  delim,
  ...,
  names = NULL,
  names_sep = NULL,
  names_repair = "check_unique",
  too_few = c("align_start", "error"),
  too_many = c("drop", "error"),
  cols_remove = TRUE
)

Arguments

.df

A data frame

cols

Columns to separate

delim

Delimiter to separate on

...

These dots are for future extensions and must be empty.

names

New column names to separate into

names_sep

Names separator

names_repair

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

too_few

What to do when too few column names are supplied

too_many

What to do when too many column names are supplied

cols_remove

Should old columns be removed

Examples

df <- tidytable(x = c("a", "a_b", "a_b", NA))

df %>%
  separate_wider_delim(x, delim = "_", names = c("left", "right"))
#> # A tidytable: 4 × 2
#>   left  right
#>   <chr> <chr>
#> 1 a     NA   
#> 2 a     b    
#> 3 a     b    
#> 4 NA    NA   

df %>%
  separate_wider_delim(x, delim = "_", names_sep = "")
#> # A tidytable: 4 × 2
#>   x1    x2   
#>   <chr> <chr>
#> 1 a     NA   
#> 2 a     b    
#> 3 a     b    
#> 4 NA    NA