Learn R Programming

tidyft (version 0.9.20)

separate: Separate a character column into two columns using a regular expression separator

Description

Given either regular expression, separate() turns a single character column into two columns. Analogous to tidyr::separate, but only split into two columns only.

Usage

separate(.data, separated_colname, into, sep = "[^[:alnum:]]+", remove = TRUE)

Value

A data.table

Arguments

.data

A data frame.

separated_colname

Column name, string only.

into

Character vector of length 2.

sep

Separator between columns.

remove

If TRUE, remove input column from output data frame.

See Also

separate, unite_dt

Examples

Run this code
df <- data.table(x = c(NA, "a.b", "a.d", "b.c"))
df %>% separate(x, c("A", "B"))
# equals to
df <- data.table(x = c(NA, "a.b", "a.d", "b.c"))
df %>% separate("x", c("A", "B"))

Run the code above in your browser using DataLab