Rev 27124 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{strsplit}\alias{strsplit}\title{Split the Elements of a Character Vector}\description{Split the elements of a character vector \code{x} into substringsaccording to the presence of substring \code{split} within them.}\usage{strsplit(x, split, extended = TRUE, fixed = FALSE)}\arguments{\item{x}{character vector, each element of which is to be split.}\item{split}{character vector containing \link{regular expression}(s)(unless \code{fixed = TRUE}) to use as \dQuote{split}. If emptymatches occur, in particular if \code{split} has length 0, \code{x} issplit into single characters. If \code{split} has length greater than1, it is re-cycled along \code{x}.}\item{extended}{logical. if \code{TRUE}, extended regular expression matchingis used, and if \code{FALSE} basic regular expressions are used.}\item{fixed}{logical. If \code{TRUE} match string exactly, otherwiseuse regular expressions.}}\value{A list of length \code{length(x)} the \code{i}-th element of whichcontains the vector of splits of \code{x[i]}.}\details{Arguments \code{x} and \code{split} will be coerced to character, soyou will see uses with \code{split = NULL} to mean\code{split = character(0)}, including in the examples below.Note that spltting into single characters can be done via\code{split=character(0)} or \code{split=""}; the two are equivalentas from \R 1.9.0.A missing value of \code{split} does not split the the correspondingelement(s) of \code{x} at all.}\seealso{\code{\link{paste}} for the reverse,\code{\link{grep}} and \code{\link{sub}} for string search andmanipulation; further \code{\link{nchar}}, \code{\link{substr}}.\link{regular expression} for the details of the pattern specification.}\examples{noquote(strsplit("A text I want to display with spaces", NULL)[[1]])x <- c(as = "asfef", qu = "qwerty", "yuiop[", "b", "stuff.blah.yech")# split x on the letter estrsplit(x,"e")unlist(strsplit("a.b.c", "."))## [1] "" "" "" "" ""## Note that 'split' is a regexp!## If you really want to split on '.', useunlist(strsplit("a.b.c", "\\\\."))## [1] "a" "b" "c"## orunlist(strsplit("a.b.c", ".", fixed = TRUE))## a useful function: rev() for stringsstrReverse <- function(x)sapply(lapply(strsplit(x, NULL), rev), paste, collapse="")strReverse(c("abc", "Statistics"))## get the first names of the members of R-corea <- readLines(file.path(R.home(),"AUTHORS"))[-(1:8)]a <- a[(0:2)-length(a)](a <- sub(" .*","", a))# and reverse themstrReverse(a)}\keyword{character}