[英]merging two time-series into a new data frame using R
Hi I have a small discontinuous time-series data (mWL): 嗨我有一个小的不连续时间序列数据(mWL):
> print(mWL)
dt Q1 Q2 R1 R2 S1 S2 S3 N1 N2 O
1 2013-05-25 12:00:00 NA NA NA NA NA NA NA NA NA NA
2 2013-05-25 13:20:00 NA NA NA NA NA NA NA NA NA NA
3 2013-05-25 15:20:00 NA NA 4.107 4.167 NA NA NA NA NA NA
4 2013-05-25 15:40:00 5.833 6.405 NA NA NA NA NA NA NA NA
5 2013-05-25 17:00:00 NA NA NA NA NA NA NA NA NA 6.957
6 2013-05-25 17:20:00 NA NA NA NA NA NA NA 6.088 7.307 NA
And I also have a rather big continuous (every 20 min) database (H) which also contains a few of the time measuremnts of 'mWL' 而且我还有一个相当大的连续(每20分钟)数据库(H),它还包含一些'mWL'的时间测量
tail(H,n=80)
time e1
13782 2013-05-25 09:40:00 12.8452
13783 2013-05-25 10:00:00 12.8429
13784 2013-05-25 10:20:00 12.8376
13785 2013-05-25 10:40:00 12.8362
13786 2013-05-25 11:00:00 12.8338
13787 2013-05-25 11:20:00 12.8359
13788 2013-05-25 11:40:00 12.8371
13789 2013-05-25 12:00:00 12.8380
13790 2013-05-25 12:20:00 12.8355
13791 2013-05-25 12:40:00 12.8380
13792 2013-05-25 13:00:00 12.8396
13793 2013-05-25 13:20:00 12.8418
13794 2013-05-25 13:40:00 12.8403
13795 2013-05-25 14:00:00 12.8427
13796 2013-05-25 14:20:00 12.8443
13797 2013-05-25 14:40:00 12.8453
13798 2013-05-25 15:00:00 12.8460
13799 2013-05-25 15:20:00 12.8483
13800 2013-05-25 15:40:00 12.8508
13801 2013-05-25 16:00:00 12.8528
13802 2013-05-25 16:20:00 12.8547
13803 2013-05-25 16:40:00 12.8559
13804 2013-05-25 17:00:00 12.8579
13805 2013-05-25 17:20:00 12.8594
13806 2013-05-25 17:40:00 12.8613
I want to make a new data frame of the size of 'mWL' (ie only 6 row) with H$e1 data merged on same time; 我想创建一个大小为'mWL'的新数据框(即只有6行),同时合并H $ e1数据; but when I try to use align.time, the data frame remains big and the 'mWL' data repeats!!
但是当我尝试使用align.time时,数据框仍然很大并且'mWL'数据重复!
require(xts)
Hsort<-align.time(xts(H[,2],as.POSIXct(H[,1])), n=1200)
mWLsort<-align.time(xts(mWL[,2],as.POSIXct(mWL[,1])), n=1200)
merge(H, mWLsort)
any suggestion?? 任何建议?
The default for all
is TRUE for merge.zoo
from which merge.xts
(if it exists) probably either inherits or follows the lead of the zoo authors. 对于
merge.zoo
, all
的默认值为TRUE, merge.xts
(如果存在)可能继承或遵循动物园作者的引导。 So set all = c(FALSE, TRUE)
if you just want the items that are in the second object to be matched. 因此
all = c(FALSE, TRUE)
如果您只想匹配第二个对象中的项目,请设置all = c(FALSE, TRUE)
。 (This is the opposite of the default setting for all
in base::merge
so I can certainly understand if you were confused. I was until I looked at: (这与
base::merge
all
默认设置相反,所以我当然可以理解你是否感到困惑。直到我看到:
help(package="zoo", merge.zoo)
help(package="xts", merge.xts)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.