Suppose I have the following two XTS...
a <- c(1,2,3,4)
b <- c(2,4,6,8)
x <- xts(cbind(a,b),order.by = as.Date(c("2015-01-02","2015-01-05","2015-01-06","2015-01-07")))
x
and
c <- c("a","b","b","a","a","b")
d <- c(10,20,10,30,20,40)
y <- xts(cbind(c,d),order.by = as.Date(c("2015-01-02","2015-01-02","2015-01-05","2015-01-06","2015-01-07","2015-01-07")))
y
These give me...
a b
2015-01-02 1 2
2015-01-05 2 4
2015-01-06 3 6
2015-01-07 4 8
and
c d
2015-01-02 "a" "10"
2015-01-02 "b" "20"
2015-01-05 "b" "10"
2015-01-06 "a" "30"
2015-01-07 "a" "20"
2015-01-07 "b" "40"
I'd like to get the following XTS...
a b
2015-01-02 10 20
2015-01-05 NA 10
2015-01-06 30 NA
2015-01-07 20 40
I tried a couple of different methods such as using the functions match and coredata but wasn't able to get the exact answer. I think maybe starting with the first XTS with blank values and then filling it in with the values from the second XTS will work best. Not sure how to do that though.