Given the various single-line xts objects:
z1 = xts(t(c("9902"=0,"9903"=0,"9904"=0,"9905"=2,"9906"=2)),as.Date("2015-01-01")) z2 = xts(t(c("9902"=3,"9903"=4,"9905"=6,"9906"=5,"9908"=8)),as.Date("2015-01-02")) z3 = xts(t(c("9901"=1,"9903"=3,"9905"=5,"9906"=6,"9907"=7,"9909"=9)),as.Date("2015-01-03"))
I want to combine them into one xts object. But cbind(z1,z2,z3) gives:
X9902 X9903 X9904 X9905 X9906 X9902.1 X9903.1 X9905.1 X9906.1 X9908 X9901 X9903.2 X9905.2 X9906.2 X9907 X9909 2015-01-01 0 0 0 2 2 NA NA NA NA NA NA NA NA NA NA NA 2015-01-02 NA NA NA NA NA 3 4 6 5 8 NA NA NA NA NA NA 2015-01-03 NA NA NA NA NA NA NA NA NA NA 1 3 5 6 7 9
While I expect:
9901 9902 9903 9904 9905 9906 9907 9908 9909 2015-01-01 0 0 0 0 2 2 0 0 0 2015-01-02 0 3 4 0 6 5 0 8 0 2015-01-03 1 0 3 0 5 6 7 0 9
(I can get the NA to change to zeros by specifying fill=0 , i.e. cbind(z1,z2,z3,fill=0) .)
rbind(z1,z2,z3) complains that rows have different numbers of columns. But I believe that if the missing columns were added to each xts object in advance, what would be a good approach?
Real data can contain 1000 rows and several hundred columns (after merging), so I mean efficiency.