R/separate.R
separate.Rd
Given either regular expression,
separate()
turns a single character column into two columns.
Analogous to tidyr::separate
, but only split into two columns only.
separate(.data, separated_colname, into, sep = "[^[:alnum:]]+", remove = TRUE)
A data.table
df <- data.table(x = c(NA, "a.b", "a.d", "b.c"))
df %>% separate(x, c("A", "B"))
#> A B
#> <char> <char>
#> 1: <NA> <NA>
#> 2: a b
#> 3: a d
#> 4: b c
# equals to
df <- data.table(x = c(NA, "a.b", "a.d", "b.c"))
df %>% separate("x", c("A", "B"))
#> A B
#> <char> <char>
#> 1: <NA> <NA>
#> 2: a b
#> 3: a d
#> 4: b c