I noticed some strange xts behavior when trying to split an object that goes a long way. The behavior of split changes in the era.
#Create some data dates <- seq(as.Date("1960-01-01"),as.Date("1980-01-01"),"days") x <- rnorm(length(dates)) data <- xts(x, order.by=dates)
If we divide the xts object by the week, it will define the last day of the week as Monday until 1970. After 1970, he defines it as Sunday (expected behavior).
Calendar 1960
Calendar 1979
This seems like a problem only for weeks, not months or years.
The behavior is likely to be related to the following, although I'm not sure why it will only apply to weeks. From xts cran .
For dates before the era (1970-01-01), the end time is 59.0000 seconds. This is due to an error / function in the implementation of R asPOSIXct and mktime0 at the C-source level. This limits the accuracy of ranges to 1970 to 1 minute of granularity with the current time traversal of xts.
My workaround was to shift the dates before dividing the objects into data until 1970, if I was dividing into weeks. I expect someone else to have a more elegant solution (or a way to avoid a mistake).
EDIT: To be clear what the question is, I am looking for an answer that a) indicates why this happens (so I can better understand the nature of the error and therefore avoid it) and / or b) the best way to solve the problem.
source share