[R] removing characters from a string

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Apr 12 15:50:23 CEST 2005

Using help.start() and searching on keyword "character" or using
help.search(keyword="character") will show you what you have missed.

As others have pointed out, you have missed the power of regular 
expressions (despite that being how these things are done in Perl).
Also, strsplit() can be very powerful.

On Tue, 12 Apr 2005, Vivek Rao wrote:

> Is there a simple way in R to remove all characters
> from a string other than those in a specified set? For
> example, I want to keep only the digits 0-9 in a
> string.
> In general, I have found the string handling abilities
> of R a bit limited.

Your exploration of them seems more than a bit limited.

> (Of course it's great for stats in general). Is there a good reference 
> on this? Or should R programmers dump their output to a text file and 
> use something like Perl or Python for sophisticated text processing?
> I am familiar with the basic functions such as nchar,
> substring, as.integer, print, cat, sprintf etc.

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list