Yes, but the answer is likely to depend on the actual patterns of strings in 
your real data, so the sooner you go find a book or tutorial on regular 
expressions the better.  This is decidedly not R specific and there are already 
lots of resources out there.

Given the example you provide,  the pattern "age$" should work. However, that 
is probably not sufficiently selective for a practical data set so start 
learning to fish (design regex patterns) yourself. 
-- 
Sent from my phone. Please excuse my brevity.

On May 3, 2016 10:45:42 PM PDT, Steven Yen <sye...@gmail.com> wrote:
>Dear all
>In the grep command below, is there a way to identify only "age" and
>not "age2"? In other words, I like to greb "age" and "age2"
>separately, one at a time. Thanks.
>
>x<-c("abc","def","rst","xyz","age","age2")
>x
>
>[1] "abc"  "def"  "rst"  "xyz"  "age"  "age2"
>
>grep("age2",x)
>
>[1] 6
>
>grep("age",x) # I need to grab "age" only, not "age2"
>
>[1] 5 6
>
>______________________________________________
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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 -- To UNSUBSCRIBE and more, see
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