I am working with a time series data set which is in Julian days since the origin (1-1-1). I am using function chron from chron package to do the conversion from Julian days to gregorian date. However, in order to check my result, besides testing my results in R I also decided to compare it with a couple of websites (for exemple, http://www.timeanddate.com/date/durationresult.html) that counts the number of days in between two dates. Below is a reproducible code:
library('chron')
date <- seq(from=729391,to=729756,by=30)
d.year <- 1
d.month <- 1
d.day <- 1
new.date <- chron(date,origin. = c(d.year,d.month,d.day), out.format = 'year-d-m')
When I run the following code I should get 0 for all elements, if the conversion was done correctly.In fact I do get 0:
> library('lubridate')
> ymd(as.character(new.date)) - ymd('0001-01-01') - date
Time differences in days
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0
When a compare it with the websites I get different results from. For example for the element new.date[1]
(which is 1998-Jan-03
) I use the website cited above to count the number of day in between 0001-01-01
and 1998-Jan-03
and I get 729,393
while I should get 729,391
. I know the website is including the start date in the computation, even though there is still a difference of 1
. Thank you if you could shed any light on this.