Re: [R] removing characters from a string

From: Martin Maechler <>
Date: Tue 12 Apr 2005 - 23:15:21 EST

>>>>> "Vivek" == Vivek Rao <>
>>>>> on Tue, 12 Apr 2005 05:54:55 -0700 (PDT) writes:

    Vivek> Is there a simple way in R to remove all characters
    Vivek> from a string other than those in a specified set? For
    Vivek> example, I want to keep only the digits 0-9 in a
    Vivek> string.

    Vivek> In general, I have found the string handling abilities
    Vivek> of R a bit limited. (Of course it's great for stats in
    Vivek> general). Is there a good reference on this? Or should
    Vivek> R programmers dump their output to a text file and use
    Vivek> something like Perl or Python for sophisticated text     Vivek> processing?

    Vivek> I am familiar with the basic functions such as nchar,     Vivek> substring, as.integer, print, cat, sprintf etc.

It depends on your "etc":

The above is pretty trivial using gsub(), but since you sound sophisticated enough to proclaim missing R abilities, I leave the exercise to you.

Martin mailing list PLEASE do read the posting guide! Received on Wed Apr 13 00:00:37 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:07 EST