strptime and non ISO date format
Thank to Dirk and Patrick. I need to read help pages more carefully next time.
On 15 May 2003 at 19:24, Dirk Eddelbuettel wrote:
On Fri, May 16, 2003 at 01:36:04AM +0200, Petr Pikal wrote:
I have a character vector of dates something like:
timevec<-c("15.5.2003 00:00", "15.5.2003 00:01", "15.5.2003 00:02",
"15.5.2003 00:03","15.5.2003 00:04")
and I would like to transform it to some more convenient date class.
Is there a way how to do it directly without previous reformating to
ISO like structure and adding a seconds to it.
I tried direct transformation but it does not work as I expected (or
as I understood from help pages :-).
strptime(timevec,"%m.%d.%y %H:%M")
[1] NA NA NA NA NA
You have the month and day mixed up, and also asked for two-digit year when you really have four digits. Correcting both of these does the trick: edd at chibud:~> R --silent
timevec<-c("15.5.2003 00:00", "15.5.2003 00:01", "15.5.2003 00:02",
+ "15.5.2003 00:03","15.5.2003 00:04")
strptime(timevec,"%d.%m.%Y %H:%M")
[1] "2003-05-15 00:00:00" "2003-05-15 00:01:00" "2003-05-15 00:02:00" [4] "2003-05-15 00:03:00" "2003-05-15 00:04:00" Hth, Dirk -- Don't drink and derive. Alcohol and algebra don't mix.
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Petr petr.pikal at precheza.cz p.pik at volny.cz