[R] Search list of elements for a specific pattern

arun smartpink111 at yahoo.com
Fri Jun 22 18:55:46 CEST 2012


Hi,
You could try this;

dat2<-read.table(text="
     Alu
1        AluJ
2  AluJ/F(R)AM
3     monomer
4    AluJ/FLAM
5    AluJ/FRAM
6 AluJ/monomer
7        AluJb
8        JBF
9       FRAM
",sep="",header=TRUE)

 subset(dat2,grepl("Alu",dat2$Alu))
           Alu
1         AluJ
2  AluJ/F(R)AM
4    AluJ/FLAM
5    AluJ/FRAM
6 AluJ/monomer
7        AluJb


A.K.


     



----- Original Message -----
From: Joshua Budman <josh.budman at gmail.com>
To: R-help at r-project.org
Cc: 
Sent: Friday, June 22, 2012 12:14 PM
Subject: [R] Search list of elements for a specific pattern

Hi,
I have a list of mutations, called "mutList", of the form:

> head(mutList)
            Alu
1         AluJ
2  AluJ/F(R)AM
3    AluJ/FLAM
4    AluJ/FRAM
5 AluJ/monomer
6        AluJb

It contains about 500 elements and not all of them contain the  
sequence "Alu". I tried using this code:
Alu<-mutList[which(grep("Alu",mutList)==1)]

But that simply returned all of them elements in the list. Is there a  
way to modify the list such that I have only the elements containing  
"Alu" in the new list? Help would be appreciated!

Josh


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




More information about the R-help mailing list