rdataframelubridateposixlt

"Error in as.POSIXlt.numeric(value) : 'origin' must be supplied" When Trying To Add POSIXlt To Dataframe


I'm looking to write a script that can simply correct dates in a data frame (observations) that have two digit years to have four digits. I have all of the logic, but I get an error when I run this code:

observations[1,"Datetime_UTC"] <- observations[1,"Datetime_UTC"] + years(2000)

This line results in:

# Error in as.POSIXlt.numeric(value) : 'origin' must be supplied

How do I resolve this error?

Thank you!


Solution

  • If your dates are stored with some regular formatting, but with 2-digit years, just let lubridate functions handle it. They can handle most delimiters (even unusual ones).

    library(lubridate)
    ymd("20/11/9")
    "2020-11-09"
    dmy("31-1-90")
    "1990-01-31"
    mdy("3_07_00")
    "2000-03-07"