[R] characters in a string

Romain Francois romain.francois at dbmail.com
Wed Sep 15 17:37:26 CEST 2010


Le 15/09/10 17:16, rajeshj at cse.iitm.ac.in a écrit :
>
>
> Hi,
>
> I need to check if a string "<rh>a,b,c,d<rh>" is delimited by two"<rh>" 's as efficiently as possible(I need to do this a lot of times) and return TRUE. Can someone suggest a good technique?

Hi Rajesh,

 > f <- function( x ) grepl( "^<rh>.*<rh>$", x )
 > f( "<rh>a,b,c,d<rh>" )
[1] TRUE

See ?grepl for details.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/cCmbgg : Rcpp 0.8.6
|- http://bit.ly/bzoWrs : Rcpp svn revision 2000
`- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th



More information about the R-help mailing list