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! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 13.04 (raring) X 11.0.11303000 http://www.childpsy.net/ http://www.memritv.org http://truepeace.org http://camera.org http://openvotingconsortium.org http://palestinefacts.org Experience comes with debts.
On Sep 18, 2013, at 10:42 AM, Sam Steingold <sds at gnu.org> wrote:> 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!The latter. From ?strplit in the description of 'split': If split has length greater than 1, it is re-cycled along x. Thus, in the first example above, ',' is used for the first element of your vector and ';' is used for the second and so on. Regards, Marc Schwartz
Hi, You could try: strsplit(c("a,b;c","d;e,f"),",|;") #[[1]] #[1] "a" "b" "c" # #[[2]] #[1] "d" "e" "f" A.K. ----- Original Message ----- From: Sam Steingold <sds at gnu.org> To: r-help at 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! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 13.04 (raring) X 11.0.11303000 http://www.childpsy.net/ http://www.memritv.org http://truepeace.org http://camera.org http://openvotingconsortium.org http://palestinefacts.org Experience comes with debts. ______________________________________________ R-help at 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.