Re: [R] grep(): returning the matched value

From: Macnamara, Aidan <aidan.macnamara_at_imperial.ac.uk>
Date: Mon, 14 Jan 2008 14:09:53 -0000

Apologies, that should be  

grep("[[:digit:]]{2}", x, value=T) returns "pjhj24jhjhd"  

obviously.  


From: r-help-bounces_at_r-project.org on behalf of Macnamara, Aidan Sent: Mon 1/14/2008 14:04
To: r-help_at_r-project.org
Subject: [R] grep(): returning the matched value

Hi,

I'm looking to use the grep function (or something else) to return the matched pattern as opposed to the whole element. For example:

x <- c("pjhj24jhjhd")
grep("[[:digit:]]{2}", x, value=T) returns "people", whereas I simply want "24".

Any help would be appreciated,

Thanks, Aidan

        [[alternative HTML version deleted]]



R-help_at_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.

        [[alternative HTML version deleted]]



R-help_at_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. Received on Mon 14 Jan 2008 - 14:17:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Jan 2008 - 14:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive