grep command

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

grep command

syen04
Dear all
In the grep command below, is there a way to identify only "age" and
not "age2"? 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

Also, I post message to [hidden email] and that's subject to
approval by the list moderator. Am I sending it to the wrong address?

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: grep command

Ivan Calandra-4
What about?

grep("^age$", x)

Ivan

--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 03/05/2016 à 12:38, Steven Yen a écrit :

> Dear all
> In the grep command below, is there a way to identify only "age" and
> not "age2"? 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
>
> Also, I post message to [hidden email] and that's subject to
> approval by the list moderator. Am I sending it to the wrong address?
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: grep command

Ivan Calandra-4
In reply to this post by syen04
Oh, and regarding the moderator approval, I guess it's because you're a
new user to the list.

Ivan

--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 03/05/2016 à 12:38, Steven Yen a écrit :

> Dear all
> In the grep command below, is there a way to identify only "age" and
> not "age2"? 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
>
> Also, I post message to [hidden email] and that's subject to
> approval by the list moderator. Am I sending it to the wrong address?
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: grep command

Jeff Newmiller
In reply to this post by Ivan Calandra-4
Isn't that just an inefficient way to do

"age" == x

?
--
Sent from my phone. Please excuse my brevity.

On May 3, 2016 3:57:05 AM PDT, Ivan Calandra <[hidden email]> wrote:

>What about?
>
>grep("^age$", x)
>
>Ivan
>
>--
>Ivan Calandra, PhD
>Scientific Mediator
>University of Reims Champagne-Ardenne
>GEGENAA - EA 3795
>CREA - 2 esplanade Roland Garros
>51100 Reims, France
>+33(0)3 26 77 36 89
>[hidden email]
>--
>https://www.researchgate.net/profile/Ivan_Calandra
>https://publons.com/author/705639/
>
>Le 03/05/2016 à 12:38, Steven Yen a écrit :
>> Dear all
>> In the grep command below, is there a way to identify only "age" and
>> not "age2"? 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
>>
>> Also, I post message to [hidden email] and that's subject to
>> approval by the list moderator. Am I sending it to the wrong address?
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
>______________________________________________
>[hidden email] 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]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: grep command

Pages, Herve
On 05/03/2016 06:05 AM, Jeff Newmiller wrote:
> Isn't that just an inefficient way to do
>
> "age" == x

Yep, it's an inefficient way to do which(x == "age").

H.

>
> ?
>

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] 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.