separate

From tidyr v0.1
0th

Percentile

Separate one column into multiple columns.

Given either regular expression or a vector of character positions, separate() turns a single character column into multiple columns.

Usage
separate(data, col, into, sep = "[^[:alnum:]]+", remove = TRUE,
  convert = FALSE, ...)
Arguments
col
Bare column name.
data
A data frame.
into
Names of new variables to create as character vector.
sep
Separator between columns.

If character, is interpreted as a regular expression. The default value is a regular expression that matches any sequence of non-alphanumeric values.

If numeric, interpreted as positions to split at. Positive values st

remove
If TRUE, remove input column from output data frame.
convert
If TRUE, will run type.convert with as.is = TRUE on new columns. This is useful if the component columns are integer, numeric or logical.
...
Other arguments passed on to strsplit to control how the regular expression is processed.
Aliases
  • separate
Examples
library(dplyr)
df <- data.frame(x = c("a.b", "a.d", "b.c"))
df %>% separate(x, c("A", "B"))
Documentation reproduced from package tidyr, version 0.1, License: MIT + file LICENSE

Community examples

nicholas.kobel@gmail.com at Oct 1, 2019 tidyr v0.8.3

If a period is the separator, must use regex where `sep = "[.]"`. This is helpful if you did `do.call(rbind.data.frame, my_list) %>% rownames_to_column("study_area")` ``` > df <- data.frame(x = c("study area 1.1", "study area 1.2", "study area 1.3", "study area 2.1", "study area 2.2")) > df %>% separate(x, c("study area", NA), sep = "[.]") study area 1 study area 1 2 study area 1 3 study area 1 4 study area 2 5 study area 2 ```

ste.bif68@gmail.com at Dec 8, 2017 tidyr v0.7.2

### Numeric Case library(dplyr) df <- data.frame(x = c(11, 21, 13, 41)) df %>% separate(x, c("A", "B"),sep=1)