-------- Original-Nachricht -------- > Datum: Tue, 14 Feb 2012 10:18:33 -0500 > Von: Sarah Goslee <sarah.gos...@gmail.com> > An: Johannes Radinger <jradin...@gmx.at> > CC: R-help@r-project.org > Betreff: Re: [R] Wildcard for indexing?
> Hi, > > You should probably do a bit of reading about regular expressions, but > here's one way: > > On Tue, Feb 14, 2012 at 10:10 AM, Johannes Radinger <jradin...@gmx.at> > wrote: > > Hi, > > > > -------- Original-Nachricht -------- > >> Datum: Tue, 14 Feb 2012 09:59:39 -0500 > >> Von: "R. Michael Weylandt" <michael.weyla...@gmail.com> > >> An: Johannes Radinger <jradin...@gmx.at> > >> CC: R-help@r-project.org > >> Betreff: Re: [R] Wildcard for indexing? > > > >> I think the grep()-family (regular expressions) will be the easiest > >> way to do this, though it sounds like you might prefer grepl() which > >> returns a logical vector: > >> > >> ^[AB] # Starts with either an A or a B > >> ^A_ # Starting with A_ > >> > >> a <- c("A_A","A_B","C_A","BB","A_Asd" > >> grepl("^[AB]", a) > >> grepl("^A_") > > > > Yes grepl() is what I am looking for. > > is there also something like an OR statement e.g. if I want to > > select for elements that start with "as" OR "df"? > > > a <- c("as1", "bb", "as2", "cc", "df", "aa", "dd", "sdf") > > grepl("^as|^df", a) > [1] TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE > > > The square brackets match any of those characters, so are good > for single characters. For more complex patterns, | is the or symbol. > ^ marks the beginning. Thank you so much Sarah! I tried that | symbol intuitively, there was just a problem with the quotation marks :( Now everything is solved... /johannes > > Sarah > > -- > Sarah Goslee > http://www.functionaldiversity.org -- ______________________________________________ R-help@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.