Re: [R] removing characters from a string

From: Robin Hankin <r.hankin_at_soc.soton.ac.uk>
Date: Tue 12 Apr 2005 - 23:16:58 EST

Hi

Try

  gsub("[^0-9]","","1111af-456utaDFasswe34534%^&%*$h567890ersdfg") [1] "111145634534567890"

HTH rksh

On Apr 12, 2005, at 01:54 pm, 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. (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.
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Apr 13 00:09:45 2005

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