I have 3 xts objects all of whose indicies are 'Date' objects:
> a
a
1995-01-03 1.76
1995-01-04 1.69
> b
b
1995-01-03 1.67
1995-01-04 1.63
> c
c
1995-01-03 1.795
1995-01-04 1.690
To verify the indices are the same:
> index(a) == index(b)
[1] TRUE TRUE
> index(a) == index(c)
[1] TRUE TRUE
Now I'm seeing this odd behaviour:
> merge.xts(a,b)
a b
1995-01-03 NA 1.67
1995-01-03 1.76 NA
1995-01-04 NA 1.63
1995-01-04 1.69 NA
While the following merge works fine:
> merge.xts(a,c)
a c
1995-01-03 1.76 1.795
1995-01-04 1.69 1.690
I can't figure out what could possibly be going on here. Any idea?
Update:
> dput(a)
structure(c(1.76, 1.69), .indexCLASS = "Date", .indexTZ = "", .CLASS = "xts", class = c("xts",
"zoo"), index = structure(c(789168240, 789254580), tzone = "", tclass = "Date"), .Dim = c(2L,
1L), .Dimnames = list(NULL, "a"))
> dput(b)
structure(c(1.67, 1.63), .indexCLASS = "Date", .indexTZ = "", .CLASS = "xts", class = c("xts",
"zoo"), index = c(789109200, 789195600), .Dim = c(2L, 1L), .Dimnames = list(
NULL, "b"))
> dput(c)
structure(c(1.795, 1.69), .indexCLASS = "Date", .indexTZ = "", .CLASS = "xts", class = c("xts",
"zoo"), index = c(789109200, 789195600), .Dim = c(2L, 1L), .Dimnames = list(
NULL, "c"))
Indeed, the problem is that the indices are not identical (as verified by .index(a) == .index(b)
). Converting to numeric then recreating an xts and recomputing the dates with asDate
fixed the problem.
This objects were created from the to.daily
method from xts.