Note that this issue was raised on StackOverflow recently.
http://stackoverflow.com/questions/7678090/xts-merge-odd-behaviour
Here's the solution:
index(a) - index(a)
index(b) - index(b)
merge(a,b)
ZWD.UGX SCHB.Close
2010-03-31 NA 28.02
2010-04-01 7.6343 NA
I have two xts objects, call them a and b, and am trying to merge them...
class(a)
[1] xts zoo
class(b)
[1] xts zoo
head(a)
2010-04-01 7.6343
2010-04-02 7.6343
2010-04-03 7.5458
2010-04-04 7.4532
2010-04-05 7.4040
2010-04-06 7.3317
head(b)
2010-04-01 568.80
2010-04-05 571.01
Hmm, that's quite puzzling. I don't know but I'd willing to guess the
time/date stamps on a,b are more different than the output is leading us to
believe. My experience is that there's always more to a time/date object to
trick us up than one would expect.
If you could, dput() them so we can see
On 26 August 2011 03:37, R. Michael Weylandt michael.weyla...@gmail.com wrote:
If you could, dput() them so we can see everything about them. You also
might see if merge() gives you more expected behavior
Ok...
dput(a)
structure(c(7.6343, 7.6343, 7.5458, 7.4532, 7.404, 7.3317), class =
Hi
On 26 August 2011 03:37, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
If you could, dput() them so we can see everything about them. You
also
might see if merge() gives you more expected behavior
Ok...
dput(a)
structure(c(7.6343, 7.6343, 7.5458, 7.4532, 7.404,
Hi:
Try this:
require('xts')
merge.zoo(zoo(a), zoo(b), all = c(TRUE, TRUE))
ZWD.UGX SCHB.Close
2010-03-31 NA 28.02
2010-04-01 7.6343 NA
2010-04-02 7.6343 NA
2010-04-03 7.5458 NA
2010-04-04 7.4532 28.30
2010-04-05 7.4040 28.38
I was rather too quick
It has probably something to do with versions of zoo and xts
after updating to zoo 1.7.4 and xts 0.8.2 I got with your examples
merge(a,b)
ZWD.UGX SCHB.Close
2010-04-01 NA 28.02
2010-04-01 7.6343 NA
2010-04-02 7.6343 NA
2010-04-03
This seems to be the easiest way to handle the problem:
a = xts(coredata(a), time(a))
b = xts(coredata(b), time(b))
merge(a,b)
ZWD.UGX SCHB.Close
2010-03-31 NA 28.02
2010-04-01 7.6343 NA
2010-04-02 7.6343 NA
2010-04-03 7.5458 NA
2010-04-04
8 matches
Mail list logo