2015-06-11 81 views
1

我有看起來像這樣的多個數據幀:結合的時間序列數據爲單個數據幀

> head(Standard.df) 
    Count.S  Date  Month  Week  Year 
552  15 2008-01-01 2008-01-01 2007-12-31 2008-01-01 
594  11 2008-01-02 2008-01-01 2007-12-31 2008-01-01 
1049 10 2008-01-03 2008-01-01 2007-12-31 2008-01-01 
511  12 2008-01-04 2008-01-01 2007-12-31 2008-01-01 
717  10 2008-01-06 2008-01-01 2007-12-31 2008-01-01 
1744  3 2008-01-07 2008-01-01 2008-01-07 2008-01-01 

> head(Guardian.df) 
    Count.G  Date  Month  Week  Year 
2624  7 2006-01-02 2006-01-01 2006-01-02 2006-01-01 
409  13 2006-01-03 2006-01-01 2006-01-02 2006-01-01 
93  13 2006-01-04 2006-01-01 2006-01-02 2006-01-01 
999  20 2006-01-05 2006-01-01 2006-01-02 2006-01-01 
1387  19 2006-01-06 2006-01-01 2006-01-02 2006-01-01 
2652  4 2006-01-07 2006-01-01 2006-01-02 2006-01-01 
2652  4 2006-01-07 2006-01-01 2006-01-02 2006-01-01 

> head(Welt.df) 
    Count.W  Date  Month  Week  Year 
2506  9 2006-01-02 2006-01-01 2006-01-02 2006-01-01 
384  12 2006-01-03 2006-01-01 2006-01-02 2006-01-01 
87  15 2006-01-04 2006-01-01 2006-01-02 2006-01-01 
947  6 2006-01-05 2006-01-01 2006-01-02 2006-01-01 
1313  19 2006-01-06 2006-01-01 2006-01-02 2006-01-01 
2532  16 2006-01-07 2006-01-01 2006-01-02 2006-01-01 

表示時間的載體是在所有的數據幀不同的長度(一些是10年,有些是8 , 等等)。理想情況下,我想將來自所有數據幀的向量合併爲一個,並將最長時間向量作爲起點,並且如果在其他數據幀中沒有對應日期 - 填寫NA s

因此,這樣的事情:

> head(Full.df) 
Count.G Count.W Count.S  Date  Month  Week  Year 
    x   x   15 2008-01-01 2008-01-01 2007-12-31 2008-01-01 
    x   x   11 2008-01-02 2008-01-01 2007-12-31 2008-01-01 
    x   x   10 2008-01-03 2008-01-01 2007-12-31 2008-01-01 
    x   x   12 2008-01-04 2008-01-01 2007-12-31 2008-01-01 
    x   x   10 2008-01-06 2008-01-01 2007-12-31 2008-01-01 
    x   x   3 2008-01-07 2008-01-01 2008-01-07 2008-01-01 

這是可能在R嗎?

回答

2

您可以試試

Reduce(function(...) merge(..., by=c('Date', 'Month', 'Week', 'Year'), 
     all=TRUE), list(Standard.df, Guardian.df, Welt.df)) 
相關問題