Separate a character column into two columns using a regular expression separator
Given either regular expression,
separate_dt()
turns a single character column into two columns.
separate_dt( .data, separated_colname, into, sep = "[^[:alnum:]]+", remove = TRUE )
.data |
A data frame. |
separated_colname |
Column name, string only. |
into |
Character vector of length 2. |
sep |
Separator between columns. |
remove |
If |
df <- data.frame(x = c(NA, "a.b", "a.d", "b.c")) df %>% separate_dt(x, c("A", "B")) # equals to df %>% separate_dt("x", c("A", "B")) # If you just want the second variable: df %>% separate_dt(x,into = c(NA,"B"))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.