Skip to content
Back to formatted view

Raw Message

Message-ID: <CAM_vju=mPogFoCyMQwwycjuuOnVvhDQnuRfWm=KeBZAK7BNyig@mail.gmail.com>
Date: 2013-03-28T15:50:45Z
From: Sarah Goslee
Subject: How to replace '$' sign?
In-Reply-To: <CA+dpOJkF9-+3r0uNMZ3sjNJAKW1eKt3MW+7AMrQ08wQfkyi9eQ@mail.gmail.com>

Hi,

If you just want to remove the $, it must be escaped because $ is a
special character in regular expressions.
> gsub("\\$", "", "$232,685.35436")
[1] "232,685.35436"


But it looks like you actually want to remove both $ and ,

Modifying your code:
> gsub("\\$|,", "", "$232,685.35436")
[1] "232685.35436"

Or my preferred idiom:
> gsub("[$,]", "", "$232,685.35436")
[1] "232685.35436"


Sarah

On Thu, Mar 28, 2013 at 11: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
>

--
Sarah Goslee
http://www.functionaldiversity.org