Learn R Programming

ribiosUtils (version 1.5-6)

strtoken: Tokenize strings by character

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

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.

References

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

See Also

strsplit

Examples

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataLab