R中两个时间序列的总和

时间:2016-05-10 09:16:30

标签: r time-series data-management

我是时间序列的初学者,我有两个不同日期的数据表,我希望有一个数据表,其中包含所有日期和定量值的总和(公司支付的金额),例如我有:

here is the first datatable with the price paied

and here is the second one

我希望有这个:

date         old_price      new_price

02/03/2015     1,7+1,2       5,7+1,7

05/05/2015      5,7+1,7       5,7+2,5

20/08/2015      5,7+2,5       2,3+2,5

08/09/2015       2,3+2,5       2,3+4,7

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我们可以尝试

d3 <- data.frame(date = c(d1$date, d2$date), stringsAsFactors=FALSE)
d3[c("old_price", "new_price")] <-  Map(function(x,y)
      Reduce(`+`,expand.grid(as.numeric(sub(",", ".", x)), 
           as.numeric(sub(",", ".", y)))), d1[-1], d2[-1])