Re: [R] How to remove $ (Dollar sign) from string
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@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.
Re: [R] How to remove $ (Dollar sign) from string
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@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 pbu...@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') __ R-help@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.
[R] How to remove $ (Dollar sign) from string
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]] __ R-help@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.
Re: [R] How to remove $ (Dollar sign) from string
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 nevil.a...@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(\ Thanks -- Nevil Amos Molecular Ecology Research Group Australian Centre for Biodiversity Monash University CLAYTON VIC 3800 Australia [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] How to remove $ (Dollar sign) from string
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) ted.hard...@wlandres.net Date: 10-Apr-2012 Time: 12:46:59 This message was sent by XFMail __ R-help@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.
Re: [R] How to remove $ (Dollar sign) from string
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 ivan.calan...@u-bourgogne.fr 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 __ R-help@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.
Re: [R] How to remove $ (Dollar sign) from string
On Tue, Apr 10, 2012 at 7:34 AM, Nevil Amos nevil.a...@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 __ R-help@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.