[R] Strsplit with a separator of ||

Berend Hasselman bhh at xs4all.nl
Thu Mar 22 08:33:02 CET 2012


On 22-03-2012, at 08:28, Berend Hasselman wrote:

> 
> On 22-03-2012, at 08:23, jing tang wrote:
> 
>> Hi,
>> 
>> I tried to use strsplit for separating a string with || like
>> strsplit(string,"\\||") but it returned each single character was separated.
>> 
>> For example:
>> 
>> strsplit("a||bc","\\||")
>> 
>> [[1]]
>> 
>> [1] "a" ""  ""  "b" "c"
>> 
>> where I want the result to be "a" and "bc". 
>> 
> 
> You should escape both \'s.

Of course I should have typed the |'s.

Berend



More information about the R-help mailing list