[R] How to replace '$' sign?
Marc Schwartz
marc_schwartz at me.com
Thu Mar 28 16:48:14 CET 2013
On Mar 28, 2013, at 10:39 AM, Christofer Bogaso <bogaso.christofer at gmail.com> wrote:
> Hello again,
>
> I want to remove "$" sign and replace with nothing in my text.
> Therefore I used following code:
>
>> gsub("$|,", "", "$232,685.35436")
> [1] "$232685.35436"
>
>
> However I could not remove '$' sign.
>
> Can somebody help me why is it so?
>
> Thanks and regards
The dollar sign is a metacharacter in regular expressions (see ?regex), thus has to be escaped to be interpreted as a literal character:
> gsub("\\$|,", "", "$232,685.35436")
[1] "232685.35436"
Regards,
Marc Schwartz
More information about the R-help
mailing list