strtoken: Tokenize strings by character

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

View source: R/string.R

Description

Tokenize strings by character in a similar way as the strsplit function in the base package. The function can return a matrix of tokenized items when index is missing. If index is given, tokenized items in the selected position(s) are returned. See examples.

Usage

1
strtoken(x, split, index, ...)

Arguments

x

A vector of character strings; non-character vectors are cast into characters.

split

A character to split the strings.

index

Numeric vector indicating which fields should be returned; if missing or set to NULL, a matrix containing all fields are returned.

...

Other parameters passed to strsplit

Value

A matrix if index is missing, NULL, or contains more than one integer indices; otherwise a character vector.

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

References

The main body of the function is modified from the strsplit2 function in the limma package.

See Also

strsplit

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
myStr <- c("HSV\t1887", "FCB\t1900", "FCK\t1948")
strsplit(myStr, "\t")

strtoken(myStr, "\t")
strtoken(myStr, "\t", index=1L)
strtoken(myStr, "\t", index=2L)

myFac <- factor(myStr)
strtoken(myFac, "\t")
strtoken(myFac, "\t", index=1L)

ribiosUtils documentation built on March 13, 2020, 2:54 a.m.