[R] Finding a gsub like function in S+ 2000

Prof Brian D Ripley ripley at stats.ox.ac.uk
Fri Feb 2 08:56:54 CET 2001


On Fri, 2 Feb 2001, Andrew Criswell wrote:

> Hello All:
>
> In R 1.2.0, one can easily change characters in a string using, for example,
> the following command,
>
> gsub("-"," ",c("1-7-1997","12-21-1997"))
> [1]  "1 7 1997"    "12 21 1997"

There is also chartr for that exact purpose.

chartr("-"," ",c("1-7-1997","12-21-1997"))

> Is there a similar command with S+ 2000?

Funny you should mention that. `S Programming' (did you ever buy it)
p.31 has a limited substitute for sub, and the same idea will do gsub.

However, since what you actually want is to substitute single chars not
regexps, you could use use AsciiToInt and substring.  Take a look at the
help function on S-PLUS 2000 to see how it could be done (from memory).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list