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.