[R] Grep command

Doran, Harold HDoran at air.org
Wed May 4 17:51:13 CEST 2016


You asked this question yesterday, and received responses on this same response. Is there a reason this is reposted?



-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Steven Yen
Sent: Wednesday, May 04, 2016 1:46 AM
To: r-help <r-help at r-project.org>
Subject: [R] Grep command

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



More information about the R-help mailing list