Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

separate..html

Separate a character column into multiple columns


Description

Separates a single column into multiple columns using a user supplied separator or regex.

If a separator is not supplied one will be automatically detected.

Note: Using automatic detection or regex will be slower than simple separators such as "," or ".".

Usage

separate.(
  .df,
  col,
  into,
  sep = "[^[:alnum:]]+",
  remove = TRUE,
  convert = FALSE,
  ...
)

Arguments

.df

A data.frame or data.table

col

The column to split into multiple columns

into

New column names to split into. A character vector.

sep

Separator to split on. Can be specified or detected automatically

remove

If TRUE, remove the input column from the output data.table

convert

TRUE calls type.convert() with as.is = TRUE on new columns

...

Arguments passed on to methods

Examples

test_df <- data.table(x = c("a", "a.b", "a.b", NA))

# "sep" can be automatically detected (slower)
test_df %>%
  separate.(x, into = c("c1", "c2"))

# Faster if "sep" is provided
test_df %>%
  separate.(x, into = c("c1", "c2"), sep = ".")

tidytable

Tidy Interface to 'data.table'

v0.6.1
MIT + file LICENSE
Authors
Mark Fairbanks [aut, cre], Abdessabour Moutik [ctb], Matt Carlson [ctb], Ivan Leung [ctb], Ross Kennedy [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.