R set default origin for as.Date

xm1 picture xm1 · Jan 13, 2018 · Viewed 14.7k times · Source

Is there a way to set default origin for as.Date? I did this function to workaround:

as.date=function(x, origin='1970-01-01') as.Date(x, origin=origin)

For example:

as.Date(0)
Error in as.Date.numeric(0) : 'origin' deve ser especificado

as.date(0)
[1] "1970-01-01"

Answer

G. Grothendieck picture G. Grothendieck · Jan 13, 2018

The zoo package adds a default origin:

library(zoo)

as.Date(0)
## [1] "1970-01-01"