Try replacing \d with \\d throughout your pattern.  The R parser is
trying to interpret the \ before the grep function ever sees it.  By
backslashing the backslashes, the parser ends up putting a single
backslash in the pattern for grep to see.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Shawn Way
> Sent: Friday, March 09, 2007 1:12 PM
> To: [email protected]
> Subject: [R] Extracting text from a character string
> 
> I have a set of character strings like below:
>    
>   > data3[1]
> [1] "CB01_0171_03-27-2002-(Sample 26609)-(126)"
> > 
>    
>   I am trying to extract the text 03-27-2002 and convert this 
> into a date for the same record.  I keep looking at the grep 
> function, however I cannot quite get it to work.
>    
>   grep("\d\d-\d\d-\d\d\d\d",data3[1],perl=TRUE,value=TRUE)
>    
>   Any hints?
>    
>   Shawn Way
> 
>  
> ---------------------------------
> Sucker-punch spam with award-winning protection.
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> [email protected] 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.
>

______________________________________________
[email protected] 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.

Reply via email to