Skip to content
Prev 360598 / 398503 Next

how to use AND in grepl

Yes it works, but let me explain what I am going to do. I extract all the names I want and then create a new column out of them for my plot. This is he whole thing I do:
  PD=subset(df,grepl("pd",Command)) //extract names in Command with only "pd"
  t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
  PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract names which contain both "pd" and "t2"
  v1=c('PD','t2','PDT2')// I create a vector with these conditions
  str_extract(df$Command,paste(v1,collaps='|')) //returning patterns, using stringr library

here I see no pattern named PDT2 but there are only PD and t2 patterns.
On Monday, May 2, 2016 8:18 AM, Tom Wright <tom at maladmin.com> wrote:
Sorry for the missed braces earlier. I was typing on a phone, not the best place to conjugate regular expressions.
Using the example you provided:
[1] FALSE FALSE FALSE FALSE  TRUE
Command
5 pd_local_abdomen_t2
On Mon, May 2, 2016 at 7:42 AM, <chalabi.elahe at yahoo.de> wrote:
Thanks Peter, you were right, the exact grepl is grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change anything in Command, when I check the size of it by sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I am sure that the size is not 0. It seems that this AND does not work.