如何将多个xts数据帧合并到单个数据框中

时间:2015-12-22 07:35:19

标签: r

我有两个数据集; dataset1和dataset2。

dataset1
               DayofWeek   EMA GOOG.Close
    2015-10-15     Thurs  7.85         UP
    2015-10-16       Fri  8.00       DOWN
    2015-10-19       Mon  8.18         UP
    2015-10-20      Tues  5.39       DOWN
    2015-10-21       Wed  2.38       DOWN
    2015-10-22     Thurs  1.98         UP
    2015-10-23       Fri  9.25       DOWN
    2015-10-26       Mon 14.29         UP
    2015-10-27      Tues 15.52         UP
    2015-10-28       Wed 15.93         UP
    2015-10-29     Thurs 15.79         UP
    2015-10-30       Fri 13.83       DOWN

dataset2
           DayofWeek   EMA AAPL.Close
2015-10-15     Thurs  0.26         UP
2015-10-16       Fri  0.18       DOWN
2015-10-19       Mon  0.23         UP
2015-10-20      Tues  0.55         UP
2015-10-21       Wed  0.69       DOWN
2015-10-22     Thurs  0.99         UP
2015-10-23       Fri  1.64         UP
2015-10-26       Mon  1.31       DOWN
2015-10-27      Tues  0.95       DOWN
2015-10-28       Wed  1.41         UP
2015-10-29     Thurs  1.76         UP
2015-10-30       Fri  1.69       DOWN

我想合并dataset1和dataset2以获得像这样的新数据集3

dataset3
           DayofWeek   EMA      Close
2015-10-15     Thurs  7.85         UP
2015-10-16       Fri  8.00       DOWN
2015-10-19       Mon  8.18         UP
2015-10-20      Tues  5.39       DOWN
2015-10-21       Wed  2.38       DOWN
2015-10-22     Thurs  1.98         UP
2015-10-23       Fri  9.25       DOWN
2015-10-26       Mon 14.29         UP
2015-10-27      Tues 15.52         UP
2015-10-28       Wed 15.93         UP
2015-10-29     Thurs 15.79         UP
2015-10-30       Fri 13.83       DOWN
2015-10-15     Thurs  0.26         UP
2015-10-16       Fri  0.18       DOWN
2015-10-19       Mon  0.23         UP
2015-10-20      Tues  0.55         UP
2015-10-21       Wed  0.69       DOWN
2015-10-22     Thurs  0.99         UP
2015-10-23       Fri  1.64         UP
2015-10-26       Mon  1.31       DOWN
2015-10-27      Tues  0.95       DOWN
2015-10-28       Wed  1.41         UP
2015-10-29     Thurs  1.76         UP
2015-10-30       Fri  1.69       DOWN

我该怎么做?

1 个答案:

答案 0 :(得分:1)

如何同步列名,然后简单地将它们重新组合在一起?

names(dataset1)<-names(dataset2)
dataset3 <- rbind(dataset1,dataset2)

您可以随后将最后一列名称更改为Close