Skip to content
Prev 299409 / 398503 Next

Splitting a character vector.

Hello,

Try the following.

open.par <- " \\("  # with a blank before '('
close.par <- "\\)"
result <- strsplit(sub(close.par, "", dd1), open.par)


Why the two '\\'? Because '(' is a meta-character so it must be escaped. 
But '\' is a meta character so it must also be escaped.

Then choose the right way to separate the two, maybe something like

ix <- rep(c(TRUE, FALSE), length(result))
unlist(result)[ix]
unlist(result)[!ix]


Hope this helps,

Rui Barradas

Em 07-07-2012 22:37, John Kane escreveu: