Re: [R] simultaneous actions of grep ???

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 26 Jun 2007 09:36:06 +0100 (BST)

On Mon, 25 Jun 2007, Stephen Tucker wrote:

> My mistake... last alternative should be:
>
> c<-subset(c,regexpr("\\.1|\\.5|\\.6|\\.99999",rownames(c)) < 0)

Or, more readably,

c <- subset(c, regexpr("\\.(1|5|6|99999)", rownames(c)) < 0)

>
> --- Stephen Tucker <brown_emu@yahoo.com> wrote:
>
>> You can list them together using "|" (which stands for 'or'):
>>
>> c<-subset(c,!rownames(c) %in%
>> grep(".1|.5|.6|.99999",rownames(c),value=T))
>>
>> but "." means any character for regular expressions, so if you meant a
>> decimal place, you probably want to escape them with a "\\":
>>
>> c<-subset(c,!rownames(c) %in%
>> grep("\\.1|\\.5|\\.6|\\.99999", rownames(c),value=T))
>>
>> Another option is
>>
>> c<-subset(c,regexpr("\\.1|\\.5|\\.6|\\.99999",c) < 0)
>>
>> because regexpr will return -1 for elements which do not contain a match.
>>
>>
>> --- Ana Patricia Martins <ana.pmartins_at_ine.pt> wrote:
>>
>>> Hello R-users and developers,
>>>
>>> Once again, I'm asking for your help.
>>>
>>> There is other way to do the same more easily for applied simultaneous
>>> grep???
>>>
>>> c<-subset(c,!rownames(c) %in% grep(".1",rownames(c),value=T))
>>> c<-subset(c,!rownames(c) %in% grep(".5",rownames(c),value=T))
>>> c<-subset(c,!rownames(c) %in% grep(".6",rownames(c),value=T))
>>> c<-subset(c,!rownames(c) %in% grep(".99999",rownames(c),value=T))

-- 
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

______________________________________________
R-help_at_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
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 26 Jun 2007 - 08:44:01 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 Tue 26 Jun 2007 - 11:32:17 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.