Quantcast

How to remove $ (Dollar sign) from string

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to remove $ (Dollar sign) from string

Nevil Amos-2
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
--
Nevil Amos
Molecular Ecology Research Group
Australian Centre for Biodiversity
Monash University
CLAYTON VIC 3800
Australia

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
ya
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

how to save multiple work space

ya
Hi guys,

I have a question. I am running 3 R sessions simultaneously for
different analysis. I found out that when R quit, only objects in one of
these sessions was saved in the work space. How can I save objects of
all 3 R sessions?

Thank you very much.

YA

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to remove $ (Dollar sign) from string

John Fox
In reply to this post by Nevil Amos-2
Dear Nevil,

You have the escape the backslash:

> sub("\\$", "", "ABC$DEF")
[1] "ABCDEF"

I hope this helps,
 John

------------------------------------------------
John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Tue, 10 Apr 2012 21:34:13 +1000
 Nevil Amos <[hidden email]> 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(\"
>
> Thanks
> --
> Nevil Amos
> Molecular Ecology Research Group
> Australian Centre for Biodiversity
> Monash University
> CLAYTON VIC 3800
> Australia
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to remove $ (Dollar sign) from string

ted.harding-3
In reply to this post by Nevil Amos-2
On 10-Apr-2012 11:34:13 Nevil Amos 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(\"
>
> Thanks
> --
> Nevil Amos
> Molecular Ecology Research Group
> Australian Centre for Biodiversity
> Monash University
> CLAYTON VIC 3800
> Australia

  sub("\\$","","ABC$DEF")
  # [1] "ABCDEF"

Logic: "$" is a metacharacter which stands for "the end of the thing";
as a check of that, instead of your

  sub("$","","ABC$DEF")

do

  sub("$","+","ABC$DEF")
  # [1] "ABC$DEF+"

Therefore "$" needs to be escaped, so you have to use "\";
but since "\" is itself a metacharacter you have to escape
that too, hence "\\$".

Hoping this hrelps,
Ted.

-------------------------------------------------
E-Mail: (Ted Harding) <[hidden email]>
Date: 10-Apr-2012  Time: 12:46:59
This message was sent by XFMail

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to remove $ (Dollar sign) from string

Ivan Calandra-2
In reply to this post by Nevil Amos-2
Hi,

Try with a double back slash:
sub("\\$","","ABC$DEF")

HTH,
Ivan

--
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
[hidden email]
http://biogeosciences.u-bourgogne.fr/calandra


Le 10/04/12 13:34, Nevil Amos a écrit :

> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to save multiple work space

Michael Weylandt
In reply to this post by ya
You'll need to save them manually to avoid name conflicts -- save.image() is the function to do so but you need to give a file name.

Michael

On Apr 10, 2012, at 7:41 AM, ya <[hidden email]> wrote:

> Hi guys,
>
> I have a question. I am running 3 R sessions simultaneously for different analysis. I found out that when R quit, only objects in one of these sessions was saved in the work space. How can I save objects of all 3 R sessions?
>
> Thank you very much.
>
> YA
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to save multiple work space

Michael Weylandt
Best I understand it yes: I'm not sure if there's an easy way to
combine sessions beyond loading them all into a single session and
then saving that.

Michael

On Tue, Apr 10, 2012 at 8:01 AM, ya <[hidden email]> wrote:

> so, objects in 3 different sessions would be saved separately into 3
> different R image file?
>
>
>
> On 2012-4-10 14:54, R. Michael Weylandt <[hidden email]> wrote:
>>
>> You'll need to save them manually to avoid name conflicts -- save.image()
>> is the function to do so but you need to give a file name.
>>
>> Michael
>>
>> On Apr 10, 2012, at 7:41 AM, ya<[hidden email]>  wrote:
>>
>>> Hi guys,
>>>
>>> I have a question. I am running 3 R sessions simultaneously for different
>>> analysis. I found out that when R quit, only objects in one of these
>>> sessions was saved in the work space. How can I save objects of all 3 R
>>> sessions?
>>>
>>> Thank you very much.
>>>
>>> YA
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to save multiple work space

PIKAL Petr
In reply to this post by Michael Weylandt
Hi

>
> You'll need to save them manually to avoid name conflicts --
save.image()
> is the function to do so but you need to give a file name.

Or it is necessary have separate folder for each R session.

Regards
Petr

>
> Michael
>
> On Apr 10, 2012, at 7:41 AM, ya <[hidden email]> wrote:
>
> > Hi guys,
> >
> > I have a question. I am running 3 R sessions simultaneously for
> different analysis. I found out that when R quit, only objects in one of

> these sessions was saved in the work space. How can I save objects of
all

> 3 R sessions?
> >
> > Thank you very much.
> >
> > YA
> >
> > ______________________________________________
> > [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to remove $ (Dollar sign) from string

Gabor Grothendieck
In reply to this post by Nevil Amos-2
On Tue, Apr 10, 2012 at 7:34 AM, Nevil Amos <[hidden email]> 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

______________________________________________
[hidden email] 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.
ya
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to save multiple work space

ya
In reply to this post by PIKAL Petr
Hi Petr and Michael,

Thank you very much for the response.

It worked! Now I can use multiple R sessions simultaneously, I just need
to save their workspace separately. And If I want those objects in the
single session, I just load them all in this session, and save the
workspace again together:)

Thank you very much. This save me lots of time!

Best regards,

ya



On 2012-4-10 15:14, Petr PIKAL wrote:

> Hi
>
>> You'll need to save them manually to avoid name conflicts --
> save.image()
>> is the function to do so but you need to give a file name.
> Or it is necessary have separate folder for each R session.
>
> Regards
> Petr
>
>> Michael
>>
>> On Apr 10, 2012, at 7:41 AM, ya<[hidden email]>  wrote:
>>
>>> Hi guys,
>>>
>>> I have a question. I am running 3 R sessions simultaneously for
>> different analysis. I found out that when R quit, only objects in one of
>> these sessions was saved in the work space. How can I save objects of
> all
>> 3 R sessions?
>>> Thank you very much.
>>>
>>> YA
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>> ______________________________________________
>> [hidden email] 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.

______________________________________________
[hidden email] 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.
ya
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to save multiple work space

ya
In reply to this post by PIKAL Petr
Hi Petr and Michael,

Thank you very much for the response.

It worked! Now I can use multiple R sessions simultaneously, I just need
to save their workspace separately. And If I want those objects in the
single session, I just load them all in this session, and save the
workspace again together:)

Thank you very much. This save me lots of time!

Best regards,

ya



On 2012-4-10 15:14, Petr PIKAL wrote:

> Hi
>
>> You'll need to save them manually to avoid name conflicts --
> save.image()
>> is the function to do so but you need to give a file name.
> Or it is necessary have separate folder for each R session.
>
> Regards
> Petr
>
>> Michael
>>
>> On Apr 10, 2012, at 7:41 AM, ya<[hidden email]>  wrote:
>>
>>> Hi guys,
>>>
>>> I have a question. I am running 3 R sessions simultaneously for
>> different analysis. I found out that when R quit, only objects in one of
>> these sessions was saved in the work space. How can I save objects of
> all
>> 3 R sessions?
>>> Thank you very much.
>>>
>>> YA
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>> ______________________________________________
>> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to remove $ (Dollar sign) from string

Giuseppe Marinelli
In reply to this post by Nevil Amos-2
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"

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to remove $ (Dollar sign) from string

Patrick Burns
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"
>
> ______________________________________________
> [hidden email] 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
[hidden email]
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

______________________________________________
[hidden email] 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.
Loading...