merge two time series with different time granularities

冷暖自知 提交于 2019-12-06 12:26:05

The lines that read in the files should be replaced as shown:

> A <- read.zoo("File1.csv", header = TRUE, tz = "", sep = ",")
> B <- read.zoo("File2.csv", header = TRUE, tz = "", sep = ",")
> merge(A, B)
                    A1 A2 B1 B2 B3
2013-08-01 12:10:21 NA NA  5  1  1
2013-08-05 00:00:00  2  1 NA NA NA
2013-08-05 00:01:00  2  1 NA NA NA
2013-08-05 00:02:00  1  1  5  1  1
2013-08-05 12:13:44 NA NA 14  1  2

Here it is in reproducible form:

Lines1 <- "   Time,                A1,  A2       
  2013-08-05 00:00:00,    2,  1               
  2013-08-05 00:01:00,    2,  1                      
  2013-08-05 00:02:00,    1,  1  
"

Lines2 <- " Time,              B1,    B2,      B3
2013-08-01 12:10:21,       5,    1,          1    
2013-08-05 00:02:00,      5,    1,          1                
2013-08-05 12:13:44,     14,    1,          2   
"

library(zoo)
A <- read.zoo(text = Lines1, header = TRUE, tz = "", sep = ",")
B <- read.zoo(text = Lines2, header = TRUE, tz = "", sep = ",")
merge(A, B)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!