I’m fairly new to R, and programming in general, and have a question. The answer is probably staring me in the face, but I’m not seeing it.
In package lubridate, one of the examples for
The answer is probably staring me in the face
With dates? No, if you're confused with date handling, you're probably paying attention. Date handling is a surprisingly messy business (even without involving computers), and the software for date-handling simply reflects this.
As to your question:
parse_date_time() and its
orders parameter are the easiest way to handle this in R. The scenario you describe is actually catered for. Check out the help page, and scroll down to the weird symbols I've put in the "orders" parameter.
require(lubridate) datestr <- c("090101", "90102") parsed <- parse_date_time(datestr, orders=c("ymd")) parsed_date <- as.Date(parsed)
 "2009-01-01" "1990-10-02"
If, on the other hand, your issue is that sometimes 90102 means '2009-01-02' and sometimes it means '1990-01-02', but it depends on which method you used to massage the data: you'll have to tell the software which case is which, just like you would a human being. :)