[R] How to remove $ (Dollar sign) from string

Giuseppe Marinelli giuseppe.marinelli at gmail.com
Sun Apr 22 11:18:00 CEST 2012


In data martedì 10 aprile 2012 13:34:13, Nevil Amos ha scritto:
> How do I remove a "$" character from a string sub() and gsub() with "$" or
> "\$" as pattern do not work.
> 
> > sub("$","","ABC$DEF")
> 
> [1] "ABC$DEF"
> 
> > sub("\$","","ABC$DEF")
> 
> Error: '\$' is an unrecognized escape in character string starting "\$"
> 
> > sub(\$,"","ABC$DEF")
> 
> Error: unexpected input in "sub(\"
> 
> Thanks

You just need a double backslash:
> sub("\\$","","ABC$DEF")
[1] "ABCDEF"



More information about the R-help mailing list