[R] About grep

Stephen Tucker brown_emu at yahoo.com
Tue Aug 7 06:47:45 CEST 2007


try

grep(paste("^",b[2],"$",sep=""),a)


your version will match "b2":

> grep("^b[2]$",c("b","b2","b3"))
[1] 2


--- Shao <xshining at gmail.com> wrote:

> Hi,everyone.
> 
> I have a problem when using the grep.
> for example:
> a <- c("aa","aba","abac")
> b<- c("ab","aba")
> 
> I want to match the whole word,so
> grep("^aba$",a)
> it returns 2
> 
> but when I used it a more useful way:
> grep("^b[2]$",a),
> it doesn't work at all, it can't find it, returning integer(0).
> 
> How can I chang the format in the second way?
> 
> Thanks.
> 
> -- 
> Shao
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 



       
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell.



More information about the R-help mailing list