This is not a general solution. But it works for this example:
cbind(rbind(xs[,1],ys[,1]), cbind(xs[,-1],ys[,-1])) abc 2013-03-10 7 NA 1 2013-03-11 6 NA 2 2013-03-12 5 NA 3 2013-03-14 3 1 NA 2013-03-15 2 2 NA 2013-03-16 1 3 NA
Remember that cbind.xts is just merge.xts . S you can get the same result using merge
merge(rbind(xs[,1],ys[,1]), merge(xs[,-1],ys[,-1])) abc 2013-03-10 7 NA 1 2013-03-11 6 NA 2 2013-03-12 5 NA 3 2013-03-14 3 1 NA 2013-03-15 2 2 NA 2013-03-16 1 3 NA
The problem with this solution is that if ys and xs have some dates, you will have a duplicate index in your xts . For example, if we replace y:
rownames(y) = as.character(Sys.Date()-3:5)
You get a duplicate index for 2013-03-14 , so im anot sure this is a valid xts object.
merge(rbind(xs[,1],ys[,1]), merge(xs[,-1],ys[,-1])) abc 2013-03-12 7 NA 1 2013-03-13 6 NA 2 2013-03-14 3 1 3 2013-03-14 5 NA NA 2013-03-15 2 2 NA 2013-03-16 1 3 NA
EDIT solution generalization:
inter <- intersect(names(ys), names(xs)) diffx <- setdiff(names(xs),inter) diffy <- setdiff(names(ys),inter) merge(rbind(xs[,inter],ys[,inter]), merge(xs[,diffx],ys[,diffy])) abc 2013-03-10 7 NA 1 2013-03-11 6 NA 2 2013-03-12 5 NA 3 2013-03-14 3 1 NA 2013-03-15 2 2 NA 2013-03-16 1 3 NA