cSplit: Split Concatenated Values into Separate Values

Description Usage Arguments Value Note Author(s) See Also Examples

Description

The cSplit function is designed to quickly and conveniently split concatenated data into separate values.

Usage

1
2
3
cSplit(indt, splitCols, sep = ",", direction = "wide", fixed = TRUE,
  drop = TRUE, stripWhite = TRUE, makeEqual = NULL,
  type.convert = TRUE)

Arguments

indt

The input data.frame or data.table.

splitCols

The column or columns that need to be split.

sep

The values that serve as a delimiter within each column. This can be a single value if all columns have the same delimiter, or a vector of values in the same order as the delimiters in each of the splitCols.

direction

The desired direction of the results, either "wide" or "long".

fixed

Logical. Should the split character be treated as a fixed pattern (TRUE) or a regular expression (FALSE)? Defaults to TRUE.

drop

Logical. Should the original concatenated column be dropped? Defaults to TRUE.

stripWhite

Logical. If there is whitespace around the delimiter in the concatenated columns, should it be stripped prior to splitting? Defaults to TRUE.

makeEqual

Logical. Should all groups be made to be the same length? Defaults to FALSE.

type.convert

Logical. Should utils::type.convert() be used to convert the result of each column? This would add a little to the execution time.

Value

A data.table with the values split into new columns or rows.

Note

The cSplit function replaces most of the earlier concat.split* functions. The earlier functions remain for compatibility purposes, but now they are essentially wrappers for the cSplit function.

Author(s)

Ananda Mahto

See Also

concat.split()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Sample data
temp <- head(concat.test)

## Split the "Likes" column
cSplit(temp, "Likes")

## Split the "Likes" and "Hates" columns --
##   they have different delimiters...
cSplit(temp, c("Likes", "Hates"), c(",", ";"))

## Split "Siblings" into a long form...
cSplit(temp, "Siblings", ",", direction = "long")

## Split "Siblings" into a long form, not removing whitespace
cSplit(temp, "Siblings", ",", direction = "long", stripWhite = FALSE)

## Split a vector
y <- c("a_b_c", "a_b", "c_a_b")
cSplit(data.frame(y), "y", "_")

mrdwab/splitstackshape documentation built on May 23, 2019, 7:16 a.m.