[R] characters in a string

2010-09-15 Thread raje...@cse.iitm.ac.in

Hi,

I need to check if a string rha,b,c,drh 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? 
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] characters in a string

2010-09-15 Thread Marc Schwartz
On Sep 15, 2010, at 10:16 AM, raje...@cse.iitm.ac.in wrote:

 
 Hi,
 
 I need to check if a string rha,b,c,drh 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? 


See ?grep and ?regex

 grepl(^rh.*rh$, rha,b,c,drh)
[1] TRUE


You can pass the entire source vector to grepl():

Vec - c(rha,b,c,drh, 1, 2, 3, 4, a, b, c, drh, rh1, 2, 3, 
4rh)

 grepl(^rh.*rh$, Vec)
[1]  TRUE FALSE FALSE  TRUE


HTH,

Marc Schwartz

__
R-help@r-project.org 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.


Re: [R] characters in a string

2010-09-15 Thread Romain Francois

Le 15/09/10 17:16, raje...@cse.iitm.ac.in a écrit :



Hi,

I need to check if a string rha,b,c,drh is delimited by tworh '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( rha,b,c,drh )
[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

__
R-help@r-project.org 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.


Re: [R] characters in a string

2010-09-15 Thread David Winsemius


On Sep 15, 2010, at 11:16 AM, raje...@cse.iitm.ac.in wrote:



Hi,

I need to check if a string rha,b,c,drh 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?


 txt - rha,b,c,drh

 grep(^rh.+rh$, txt)
[1] 1


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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.


Re: [R] characters in a string

2010-09-15 Thread raje...@cse.iitm.ac.in
great! Thanks

- Original Message -
From: David Winsemius dwinsem...@comcast.net
To: raje...@cse.iitm.ac.in
Cc: r-help r-help@r-project.org
Sent: Wed, 15 Sep 2010 21:12:27 +0530 (IST)
Subject: Re: [R] characters in a string


On Sep 15, 2010, at 11:16 AM, raje...@cse.iitm.ac.in wrote:


 Hi,

 I need to check if a string a,b,c,d is delimited by two  
  's as efficiently as possible(I need to do this a lot of  
 times) and return TRUE. Can someone suggest a good technique?

  txt - a,b,c,d
 
  grep(^.+$, txt)
[1] 1

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org 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.

David Winsemius, MD
West Hartford, CT



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.