Dear Barradas, and Dear A.K.

Thank you so much for the solutions. I got them.
I think I will study more about regular expression and apply family.

Best Regards,

Wang

2012/6/24 arun <smartpink...@yahoo.com>

> Hi,
>
> Try this:
> vec1<-c("A_cont_1", "A_cont_12", "B_treat_8", "AB_cont_22", "cont_21_Aa")
> vec2<-grep("(A){0,1}.*cont.*2",vec1)
>
> vec1[vec2]
> [1] "A_cont_12"  "AB_cont_22" "cont_21_Aa"
>
>
> A.K.
>
>
>
>
> ----- Original Message -----
> From: Zhipeng Wang <wa...@kuhp.kyoto-u.ac.jp>
> To: r-help@r-project.org
> Cc:
> Sent: Saturday, June 23, 2012 6:19 AM
> Subject: [R] matching a string with multiple conditions using grep
>
> Suppose I have a vector  ["A_cont_1", "A_cont_12", "B_treat_8",
> "AB_cont_22", "cont_21_Aa"], I hope I can extract the strings which include
> 3 short strings, say "A", "cont" and "2",  that is to say, "A_cont_12",
> "AB_cont_22" and  "cont_21_Aa" will be extract, using a relatively short
> code (using grep?).
> Would you please to give some idea? Thank you !
>
>     [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
>

        [[alternative HTML version deleted]]

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

Reply via email to