[R] Strsplit with a separator of ||

Berend Hasselman bhh at xs4all.nl
Thu Mar 22 08:28:24 CET 2012


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.

strsplit("a||bc","\\|\\|")

Berend



More information about the R-help mailing list