【问题标题】:sum of two timeseries in RR中两个时间序列的总和
【发布时间】:2016-05-10 09:16:30
【问题描述】:

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

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

非常感谢您的帮助!

【问题讨论】:

  • 你的意思是,.吗?
  • 欢迎来到 Stack Overflow @Mouna。为了将来参考,请避免使用图片来展示您的数据。示例需要可重现(使用dput()),以便其他人更容易帮助您。 Here is a link 让您开始。

标签: r time-series data-management


【解决方案1】:

我们可以试试

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])

【讨论】:

    猜你喜欢
    • 2012-06-14
    • 2020-07-16
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 2021-04-21
    • 1970-01-01
    相关资源
    最近更新 更多