[R] recognizing "(" as a character

Henrik Bengtsson hb at maths.lth.se
Sat Nov 15 15:37:48 CET 2003


You have to escape (="\\") such "special" characters, e.g.

 strsplit("abc(d)(e)", split="\\(")

or put them in brackets (matches sets of characters)

 strsplit("abc(d)(e)", split="[(]")

if you think that is more readable. Similar for gsub(), grep(),
regexpr() and friends.

Henrik Bengtsson


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Jean Eid
> Sent: den 15 november 2003 15:26
> To: r-help at stat.math.ethz.ch
> Subject: [R] recognizing "(" as a character
> 
> 
> Dear All,
> I have been trying to scan data from pdf files and use R to 
> seperate them. The following will make it clear I have a line 
> that reads "Intrepid (D)  15,977 11,956 45,143 39,014" where 
> what is in the parenthesis is either a "D" for domestic or 
> "I" for import. I want to try to strsplit the line according 
> to the full character "(D)" or "(I)"  but unfortunately R 
> recognizes this as "D", or "I" in the strsplit command. my 
> question is is there any way that I can tell R that this "(" 
> is a character. P.S. even grep() does have the same problem. 
> I know this is not a problem since "(", ")", "[", etc.. are 
> predefined in R but why is the quotation marks for strings 
> not doing its job here?
> 
> Thanks,
> Jean Eid
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://www.stat.math.ethz.ch/mailma> n/listinfo/r-help
> 
>




More information about the R-help mailing list