tstrsplit {data.table} | R Documentation

## 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.

### Details

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

### Value

A transposed list.

### See Also

`data.table`, `transpose`

### Examples

    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)][]

[Package data.table version 1.9.6 Index]