[R] How to remove $ (Dollar sign) from string
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Apr 10 14:54:32 CEST 2012
On Tue, Apr 10, 2012 at 7:34 AM, Nevil Amos <nevil.amos at monash.edu> wrote:
> 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(\"
>
Here are three ways:
sub("$", "", "ABC$DEF", fixed = TRUE)
sub("\\$", "", "ABC$DEF")
sub("[$]", "", "ABC$DEF")
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list