data.table (version 1.9.6)

tstrsplit: strsplit and transpose the resulting list efficiently

Description

This is equivalent to transpose(strsplit(...)). This is a convenient wrapper function to split a column using strsplit and assign the transposed result to individual columns. See examples.

Usage

tstrsplit(x, ..., fill=NA, type.convert=FALSE)

Arguments

x
The vector to split (and transpose).
...
All the arguments to be passed to strsplit.
fill
Default is NA. It is used to fill shorter list elements so as to return each element of the transposed result of equal lengths.
type.convert
TRUE calls type.convert with as.is=TRUE on the columns.

Value

A transposed list.

Details

It internally calls strsplit first, and then transpose on the result.

See Also

data.table, transpose

Examples

Run this code
x = c("abcde", "ghij", "klmnopq")
strsplit(x, "", fixed=TRUE)
tstrsplit(x, "", fixed=TRUE)
tstrsplit(x, "", fixed=TRUE, fill="<NA>")

DT = data.table(x=c("A/B", "A", "B"), y=1:3)
DT[, c("c1", "c2") := tstrsplit(x, "/", fixed=TRUE)][]

Run the code above in your browser using DataLab