How to get chron to convert a vector of Excel serial dates

148 views Asked by At

I am trying to convert an element of a matrix from what were Excel serial dates to a vector of Date objects before using plot().

I can create a vetor and I get the expected result:

    library(chron)

# set date origin as defined in Excel

    options(chron.origin = c(month=1, day=1, year=1900))

    test_dates <- c(40917:40920)

    test_dates
    ## [1] 40917 40918 40919 40920

    chron(test_dates, out.format = "m/d/y")

    ## [1] 01/11/12 01/12/12 01/13/12 01/14/12

But when I try to use this on my actual vector, it does not work

# first 10 vlaues in vector

pivot_pred$date

 ## [1] 40917 40918 40919 40920 40921 40922 40923 40924 40925 40926...

chron(pivot_pred$date, out.format = "m/d/y")

## Error in chron(dates. = floor(dts), times. = tms, format = format, out.format = out.format,  : 
  misspecified chron format(s) length

I'm sure this is simple but I have tried many variations and none worked. Any suggestions on what I'm doing wrong?

0

There are 0 answers