3
$\begingroup$

Is there a function that does smart date parsing in R?

I know the strftime/as.POSIXct/as.POSIXlt commands, but they require a date formatting string, or throw the error "character string is not in a standard unambiguous format". This happens even when I pass a string with more than enough information to be parseable, like "Fri Apr 29 16:43:20 GMT 2011".

It would be really nice to not bother with reverse-engineering the format every time I import dates from a new source. Is there code that already does this?

Thanks!

$\endgroup$
0
5
$\begingroup$

Try "lubridate" package, from CRAN, install in the usual way. Might help!

$\endgroup$
1
  • 1
    $\begingroup$ The ymd, dmy, etc. functions in this package look close, but don't quite solve the problem. Better than the base POSIX commands, though... $\endgroup$ – Abe Apr 30 '11 at 21:05
1
$\begingroup$

I don't know of any, and I'm not sure how it would work. Does it use the first entry, figure a template, then use that for the rest of the entries? Does it parse each entry individually, so that there is no template and each entry can be different?

In the latter case, I'd worry a bit that it would be too flexible. Maybe I'm not thinking clearly, but the reverse-engineering and fixed-template method would seem to catch more errors and would help me to be more aware of my data.

(I was about to recommend lubridate, which doesn't do what you want, but does make many date tasks easier, and while I was typing, Spacedman beat me to the punch.)

$\endgroup$
1
  • $\begingroup$ Yeah, it seems like a system like this would either be really brittle or have lots of problems with error trapping. Maybe this is a pipe dream and I should just get comfortable the process. $\endgroup$ – Abe Apr 30 '11 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.