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

Patrick Burns pburns at pburns.seanet.com
Sun Apr 22 12:41:09 CEST 2012


Why you need a double backslash is alluded
to in Circle 8.1.23 of 'The R Inferno'.

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

Pat

On 22/04/2012 10:18, Giuseppe Marinelli wrote:
> 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"
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Patrick Burns
pburns at pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')



More information about the R-help mailing list