Re: [R] Problem with the grep function

From: Alec Stephenson <astephen_at_efs.mq.edu.au>
Date: Thu 08 Jul 2004 - 17:41:04 EST


grep("^b$",nom) will match "b" only.

Alec

Alec Stephenson Department of Statistics
Macquarie University
NSW 2109, Australia

>>> "aubert@inapg.fr" <aubert@inapg.fr> 07/08/04 05:20pm >>>
Let me present to you my problem :

I have a character vector x and I would like to obtain the indices of the
elements of
this vector that yielded exactly a match.

For example, x=nom, pattern="b", I would to obtain 2 because "b" is on the
second position.

First program :
nom <- c("a","b","ab")
grep("b",nom)
2 3

Then I try the option extended =FALSE (instead of TRUE by default) and I
obtain '2 3' a second time.

Please can you help me : How can I obtain only 2 in using the grep function
(without using the match function).

Thanks you

Julie AUBERT



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 08 17:50:41 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:46 EST