合并R zoo中的时间序列数据,连接格式不正确

时间:2016-08-10 05:56:44

标签: r zoo

我是R的新手,尝试使用动物园合并4个数据集,2个数据集合并得很好。
但是其他2个数据集给我o / p如下:

TMPA

2016-08-09 23:59:55 21.703 
2016-08-09 23:59:56 21.703 
2016-08-09 23:59:57 21.703 
2016-08-09 23:59:58 21.703 
2016-08-09 23:59:59 21.703 
2016-08-10 00:00:00 21.703 

tmpB

2016-08-09 23:59:52  24.600
2016-08-09 23:59:53  24.600
2016-08-09 23:59:54  24.600
2016-08-09 23:59:55  24.600
2016-08-09 23:59:56  24.600
2016-08-09 23:59:57  24.599

代码

infoA.zoo <- read.zoo(infoA.dfH, header = TRUE, tz = "")
infoB.zoo <- read.zoo(infoB.dfH, header = TRUE, tz = "")
#dfH is data.frame 
#I am discretizing it over 1 sec.
merged = merge( tmpA, tmpB)

输出

Date                      A              B
2016-08-09 23:59:56         NA      24.600
2016-08-09 23:59:57    21.703           NA
2016-08-09 23:59:57         NA      24.599
2016-08-09 23:59:58    21.703           NA
2016-08-09 23:59:59    21.703           NA
2016-08-10 00:00:00    21.703           NA

1 个答案:

答案 0 :(得分:0)

我尝试重现你的问题,但一切正常。我唯一改变的是,我将tmpAtmpB分隔符从空格更改为';'并引用日期字符串。此外,我将参数sep=';'添加到read.zoo函数。

<强> TMPA

"2016-08-09 23:59:55";21.703 
"2016-08-09 23:59:56";21.703 
"2016-08-09 23:59:57";21.703 
"2016-08-09 23:59:58";21.703 
"2016-08-09 23:59:59";21.703 
"2016-08-10 00:00:00";21.703 

<强> tmpB

"2016-08-09 23:59:52";24.600
"2016-08-09 23:59:53";24.600
"2016-08-09 23:59:54";24.600
"2016-08-09 23:59:55";24.600
"2016-08-09 23:59:56";24.600
"2016-08-09 23:59:57";24.599

<强> - [R

# Copy tmpA string to clipboard
X <- read.zoo('clipboard', tz="", sep=';')
# Copy tmpY string to clipboard
Y <- read.zoo('clipboard', tz="", sep=';')
merge(X,Y)
                     X      Y
 2016-08-09 23:59:52 24.600     NA
 2016-08-09 23:59:53 24.600     NA
 2016-08-09 23:59:54 24.600     NA
 2016-08-09 23:59:55 24.600 21.703
 2016-08-09 23:59:56 24.600 21.703
 2016-08-09 23:59:57 24.599 21.703
 2016-08-09 23:59:58     NA 21.703
 2016-08-09 23:59:59     NA 21.703
 2016-08-10 00:00:00     NA 21.703