[R] grep and strings

K Fung fungile at yahoo.com
Tue Apr 27 03:12:29 CEST 2004


Thanks

Your suggestion works.  The fix is to use double \\
rather than single \.  Changing this makes grep work
as well.


--- Spencer Graves <spencer.graves at pdf.com> wrote:
> How about the following: 
> 
>  > tst <- c(".a.", "asdf")
>  > sum(regexpr("\\.a\\.", tst)>0)
> [1] 1
> 
>       hope this helps.  spencer graves
> 
> K Fung wrote:
> 
> >I have the following command:
> >
> >length(
> >  grep("\.a\.", names(temp)))
> >
> >where temp is a vector with names
> >
> >I want to count the number of entries that contain
> the
> >sequence of characters ".a.".  However, R seems to
> >return all entries that contain "a" (every entry
> >contains "." in this example).
> >
> >How should I fix this?  Thanks
> >
> >
> >__________________________________
> >
> >______________________________________________
> >R-help at 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
> >  
> >
> 
		
__________________________________



More information about the R-help mailing list