Re: [R] grep function with patterns list...

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 16 Oct 2006 - 13:56:46 GMT

> DF <- data.frame(pat = letters[1:3])
> grep(paste(DF$pat, collapse = "|"), letters, value = TRUE)
[1] "a" "b" "c"

On 10/16/06, Stéphane CRUVEILLER <scruveil@genoscope.cns.fr> wrote:
> Ooops sorry for html tags... Just forgot to edit the message
> before sending it...
> So back to my question:
>
> Thx for the hint, but what would I have used if "b","c" and "d"
> were values of a dataframe for instance?
>
> X is for instance a dataframe:
> >X
> Mypatterns
> 1 pattern1
> 2 pattern2
> 3 pattern3
>
> Y is another dataframe.
>
> If I do:
>
> grep(X$Mypatterns,Y) this will take into account only the first pattern...
> I could use a loop but I vaguely remember an elegant trick that combined
> grep and %in%.
>
>
> Stéphane.
>
>



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 and provide commented, minimal, self-contained, reproducible code. Received on Tue Oct 17 00:10:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 16 Oct 2006 - 15:30:10 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.