[R] extract date

Petr Pikal petr.pikal at precheza.cz
Tue Apr 5 10:37:36 CEST 2005


Dear all, 

please, is there any possibility how to extract a date from data 
which are like this:

....
"Date: Sat, 21 Feb 04 10:25:43 GMT"                                    
"Date: 13 Feb 2004 13:54:22 -0600"                                     
"Date: Fri, 20 Feb 2004 17:00:48 +0000"                                
"Date: Fri, 14 Jun 2002 16:22:27 -0400"                                
"Date: Wed, 18 Feb 2004 08:53:56 -0500"                                
"Date: 20 Feb 2004 02:18:58 -0600"                                     
"Date: Sun, 15 Feb 2004 16:01:19 +0800"                                
....

I used 

strptime(paste(substr(x,12,13), substr(x,15,17), substr(x,19,22), 
sep="-"), format="%d-%b-%Y")

which suits to lines 3:5 and 7 (such are the most common in my 
dataset) but obviously does not work with other lines. If there is no 
stightforward solution I can live with what I use now but some 
automagical function like

give.me.date.from.my.string.regardles.of.formating(x)

would be great.

Thank you.

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list