合并R中的时间序列等数据库

时间:2022-09-25 05:54:41

Given the databases

鉴于数据库

> x
     Date         Values_X Names_X
[1,] "01.01.2012" "1"      "A"    
[2,] "02.01.2012" "2"      "B"    
[3,] "01.02.2012" "3"      "C"    

and

> y
     Date         Values_Y Colors_Y
[1,] "01.01.2012" "1"      "red"    
[2,] "02.01.2012" "2"      "green"    
[3,] "01.03.2012" "3"      "blue"    

I would like to merge them into the database z

我想将它们合并到数据库z中

 Date           Values_X Names_X  Values_Y Colors_Y
[1,] "01.01.2012" "1"      "A"     "1"      "red"    
[2,] "02.01.2012" "2"      "B"     "2"      "green"   
[3,] "01.02.2012" "3"      "C"     NA         NA
[4,] "01.03.2012" NA       NA      "3"      "blue"   

considering the columns of both x and y as time series and merging them w.r.t. the common column Date. NA's should be produced in case of missing entries.

考虑x和y的列作为时间序列并将它们合并为w.r.t.公共列日期。如果缺少参赛作品,应该制作NA。

I am aware of the merge function for time series in R; unfortunately I have not been able to apply it successfully to databases so far. Any hint?

我知道R中时间序列的合并函数;遗憾的是,到目前为止,我还没有成功地将它应用于数据库。任何提示?

1 个解决方案

#1


1  

All you need to do should be

你需要做的就是

merge(x, y, by = "Date", all = TRUE)

Perhaps you forgot to use all = TRUE in which case some observations would have been dropped (check out ?merge for more information about it)

也许你忘了使用all = TRUE,在这种情况下会丢弃一些观察结果(检查出来?合并有关它的更多信息)

#1


1  

All you need to do should be

你需要做的就是

merge(x, y, by = "Date", all = TRUE)

Perhaps you forgot to use all = TRUE in which case some observations would have been dropped (check out ?merge for more information about it)

也许你忘了使用all = TRUE,在这种情况下会丢弃一些观察结果(检查出来?合并有关它的更多信息)