On 09/18/2013 09:04 AM, arun wrote:
Hi,
You could try:

strsplit(c("a,b;c","d;e,f"),",|;")

He did it with "[,;]" which is equivalent but slightly faster. The more
characters you have inside the square brackets, the more beneficial it
is to use [abcde] over a|b|c|d|e. It's also more compact and easier to
read.

H.

#[[1]]
#[1] "a" "b" "c"
#
#[[2]]
#[1] "d" "e" "f"
A.K.



----- Original Message -----
From: Sam Steingold <s...@gnu.org>
To: r-help@r-project.org
Cc:
Sent: Wednesday, September 18, 2013 11:42 AM
Subject: [R] strsplit with a vector split argument

Hi,
I find this behavior unexpected:
--8<---------------cut here---------------start------------->8---
strsplit(c("a,b;c","d;e,f"),c(",",";"))
[[1]]
[1] "a"   "b;c"

[[2]]
[1] "d"   "e,f"
--8<---------------cut here---------------end--------------->8---
I thought that it should be identical to this:
--8<---------------cut here---------------start------------->8---
strsplit(c("a,b;c","d;e,f"),"[,;]")
[[1]]
[1] "a" "b" "c"

[[2]]
[1] "d" "e" "f"
--8<---------------cut here---------------end--------------->8---
Is this a bug or did I misunderstand the docs?
Thanks!


--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to