[R] Search list of elements for a specific pattern
Sarah Goslee
sarah.goslee at gmail.com
Fri Jun 22 18:22:37 CEST 2012
You should use grepl() instead:
Alu<-mutList[grepl("Alu",mutList)]
or some variant of the above, depending on the actual structure of
mutList (which might be a data frame, but doesn't appear to be a
generic list). str() and dput() are both very useful for asking
well-formed questions.
Sarah
On Fri, Jun 22, 2012 at 12:14 PM, Joshua Budman <josh.budman at gmail.com> wrote:
> 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
>
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list