Christoph Christoph - 1 month ago 6x
R Question

Why is 365 days equal to 80000 years

I have a lubridate

and wanted to get the number of days as integer. However I get the following strange intermediate results:

i1 <- interval("2015-01-01 00:00:00", "2016-01-01 00:00:00")
i1 <- interval(ymd_hms("2015-01-01 00:00:00"), ymd_hms("2016-01-01 00:00:00")) # gives the same result
# [1] "31536000s (~365 days)"
duration(i1, units = "days")
# [1] "2724710400000s (~86340.86 years)"

Edit: Here are two working shortcuts. The latter throws a message "coercing interval to duration" (And I don't know the reason for that...)

> as.numeric(as.duration(i1), units = "days")
[1] 365
> as.numeric(i1, units = 'days')

(R version 3.3.0 dated 2016-05-03, lubridate version 1.5.6)


You misunderstand the meaning of the units argument. From the documentation,

units a character string that specifies the type of units that num refers to.

where num is the first argument. So


is equivalent to

duration(i1, units = "seconds")


duration(i1, units = "days")

means that i1 is measured in days; hence the very large number.