插值时间序列

时间:2011-11-21 13:05:04

标签: r xts

我是R的新手,但我尝试了类似合并的功能,但它不适用于我的数据,因为我有多次相似的时间。我将尝试重新澄清我的问题,并希望它会更清楚:

library('xts')
library('zoo')
Sys.setenv(TZ='Asia/Calcutta')# setting current time zone to Indian Standard Time
datII=read.table(paste('D:/shankar/R_workspace/MyRWork/data/nwp-II.dat_II.dep',sep=","),head=FALSE,fill = TRUE)
#forecast_time=strptime(as.character(dat[,2]),format='%Y%m%d%H%M',tz="Asia/Calcutta")
base_time=strptime(as.character(dat[,1],dat[,2]),format='%Y%m%d%H%M',tz="Asia/Calcutta")
#approxfun(forecast_time)
dat.xts=xts(dat[,-1],order.by=base_time)`

我有一个数据,在接下来的8天内每隔6小时更新一次,持续3天。 我把它编码如下:

执行dat.xts如下所示: 我也尝试以日期格式更改第二列(v2),但无法成功。 我的问题是我想按小时推断系列,而不是三个小时。 除了V5和V6并不重要。希望我很清楚。提前谢谢。

                                              V2     V3     V4 V5 V6
2010-05-01 00:00:00 201005010000  1.72 291.38  1  0
2010-05-01 00:00:00 201005010300  0.95 334.79  1  0
2010-05-01 00:00:00 201005010600  2.25  57.00  1  0
2010-05-01 00:00:00 201005010900  0.43  14.73  1  0
2010-05-01 00:00:00 201005011200  0.75 100.08  1  0
2010-05-01 00:00:00 201005011500  2.20 149.00  1  0
2010-05-01 00:00:00 201005011800  1.96 158.75  1  0
2010-05-01 00:00:00 201005012100  0.94 228.24  1  0
2010-05-01 00:00:00 201005020000  0.93 270.77  1  0
2010-05-01 00:00:00 201005020300  1.40 271.91  1  0
2010-05-01 00:00:00 201005020600  1.55   3.50  1  0
2010-05-01 00:00:00 201005020900  2.05  63.42  1  0
2010-05-01 00:00:00 201005021200  2.75 100.32  1  0
2010-05-01 00:00:00 201005021500  3.83 109.04  1  0
2010-05-01 00:00:00 201005021800  1.61 149.33  1  0
2010-05-01 00:00:00 201005022100  1.32 167.59  1  0
2010-05-01 00:00:00 201005030000  1.74 177.71  1  0
2010-05-01 00:00:00 201005030300  1.79 192.50  1  0
2010-05-01 00:00:00 201005030600  0.13  97.95  1  0
2010-05-01 00:00:00 201005030900  2.15 103.36  1  0
2010-05-01 00:00:00 201005031200  2.96 110.35  1  0
2010-05-01 00:00:00 201005031500  2.75 163.97  1  0
2010-05-01 00:00:00 201005031800  3.16 199.21  1  0
2010-05-01 00:00:00 201005032100  2.11 223.85  1  0
2010-05-01 00:00:00 201005040000  1.42 255.40  1  0
2010-05-01 00:00:00 201005040300  2.37 274.25  1  0
2010-05-01 00:00:00 201005040600  1.19  18.93  1  0
2010-05-01 00:00:00 201005040900  1.16  83.48  1  0
2010-05-01 00:00:00 201005041200  1.65  75.87  1  0
2010-05-01 00:00:00 201005041500  0.49  86.23  1  0
2010-05-01 00:00:00 201005041800  1.32 183.03  1  0
2010-05-01 00:00:00 201005042100  1.04 212.19  1  0
2010-05-01 00:00:00 201005050000  1.36 279.77  1  0
2010-05-01 00:00:00 201005050300  2.75 283.78  1  0
2010-05-01 00:00:00 201005050600  1.20   3.76  1  0
2010-05-01 00:00:00 201005050900  1.43  86.78  1  0
2010-05-01 00:00:00 201005051200  1.02 108.71  1  0
2010-05-01 00:00:00 201005051500  1.10 210.81  1  0
2010-05-01 00:00:00 201005051800  1.48 239.43  1  0
2010-05-01 00:00:00 201005052100  1.52 257.16  1  0
2010-05-01 00:00:00 201005060000  1.26 249.03  1  0
2010-05-01 00:00:00 201005060300  1.83 271.65  1  0
2010-05-01 00:00:00 201005060600  0.10 111.22  1  0
2010-05-01 00:00:00 201005060900  1.33  69.26  1  0
2010-05-01 00:00:00 201005061200  1.49 130.34  1  0
2010-05-01 00:00:00 201005061500  1.65 185.87  1  0
2010-05-01 00:00:00 201005061800  1.99 213.90  1  0
2010-05-01 00:00:00 201005062100  1.10 223.54  1  0
2010-05-01 00:00:00 201005070000  1.58 198.25  1  0
2010-05-01 00:00:00 201005070300  1.97 213.55  1  0
2010-05-01 00:00:00 201005070600  1.20 199.53  1  0
2010-05-01 00:00:00 201005070900  1.87 102.46  1  0
2010-05-01 00:00:00 201005071200  1.89 131.60  1  0
2010-05-01 00:00:00 201005071500  2.24 195.08  1  0
2010-05-01 00:00:00 201005071800  1.66 228.50  1  0
2010-05-01 00:00:00 201005072100  1.84 219.40  1  0
2010-05-01 00:00:00 201005080000  1.90 210.57  1  0
2010-05-01 00:00:00 201005080300  2.89 228.87  1  0
2010-05-01 00:00:00 201005080600  1.38 241.61  1  0
2010-05-01 00:00:00 201005080900  0.73 171.06  1  0
2010-05-01 00:00:00 201005081200  2.22 199.67  1  0
2010-05-01 06:00:00 201005010600  1.98  58.86  1  0
2010-05-01 06:00:00 201005010900  0.54  93.93  1  0
2010-05-01 06:00:00 201005011200  2.45 128.41  1  0
2010-05-01 06:00:00 201005011500  2.58 174.05  1  0
2010-05-01 06:00:00 201005011800  1.65 194.73  1  0
2010-05-01 06:00:00 201005012100  0.93 256.41  1  0
2010-05-01 06:00:00 201005020000  1.00 235.41  1  0
2010-05-01 06:00:00 201005020300  1.94 269.23  1  0
2010-05-01 06:00:00 201005020600  1.88   2.23  1  0
2010-05-01 06:00:00 201005020900  1.26  82.13  1  0
2010-05-01 06:00:00 201005021200  2.10 127.77  1  0
2010-05-01 06:00:00 201005021500  3.55 123.00  1  0
2010-05-01 06:00:00 201005021800  1.48 154.10  1  0
2010-05-01 06:00:00 201005022100  1.33 207.58  1  0
2010-05-01 06:00:00 201005030000  1.20 218.35  1  0
2010-05-01 06:00:00 201005030300  1.06 237.34  1  0
2010-05-01 06:00:00 201005030600  0.99  23.57  1  0
2010-05-01 06:00:00 201005030900  1.89  91.52  1  0
2010-05-01 06:00:00 201005031200  3.06 113.00  1  0
2010-05-01 06:00:00 201005031500  3.55 141.46  1  0
2010-05-01 06:00:00 201005031800  3.02 200.50  1  0
2010-05-01 06:00:00 201005032100  2.16 225.42  1  0
2010-05-01 06:00:00 201005040000  1.49 243.19  1  0
2010-05-01 06:00:00 201005040300  1.88 285.39  1  0
2010-05-01 06:00:00 201005040600  1.56  35.71  1  0
2010-05-01 06:00:00 201005040900  1.85  78.84  1  0
2010-05-01 06:00:00 201005041200  1.99  96.05  1  0
2010-05-01 06:00:00 201005041500  0.96 217.58  1  0
2010-05-01 06:00:00 201005041800  1.74 218.54  1  0
2010-05-01 06:00:00 201005042100  1.49 238.49  1  0
2010-05-01 06:00:00 201005050000  1.63 276.95  1  0
2010-05-01 06:00:00 201005050300  2.63 293.77  1  0
2010-05-01 06:00:00 201005050600  1.54 338.63  1  0
2010-05-01 06:00:00 201005050900  1.39  36.10  1  0
2010-05-01 06:00:00 201005051200  0.63  63.33  1  0
2010-05-01 06:00:00 201005051500  1.19 178.10  1  0
2010-05-01 06:00:00 201005051800  2.14 196.01  1  0
2010-05-01 06:00:00 201005052100  2.24 237.81  1  0
2010-05-01 06:00:00 201005060000  1.80 273.62  1  0
2010-05-01 06:00:00 201005060300  2.52 266.71  1  0
2010-05-01 06:00:00 201005060600  0.91 245.52  1  0
2010-05-01 06:00:00 201005060900  1.27 149.67  1  0
2010-05-01 06:00:00 201005061200  2.25 146.56  1  0
2010-05-01 06:00:00 201005061500  1.63 115.76  1  0
2010-05-01 06:00:00 201005061800  2.76 204.32  1  0
2010-05-01 06:00:00 201005062100  1.35 248.81  1  0
2010-05-01 06:00:00 201005070000  1.21 220.91  1  0
2010-05-01 06:00:00 201005070300  1.79 236.16  1  0
2010-05-01 06:00:00 201005070600  0.92 161.52  1  0
2010-05-01 06:00:00 201005070900  1.83 124.90  1  0
2010-05-01 06:00:00 201005071200  2.99 153.84  1  0
2010-05-01 06:00:00 201005071500  2.65 189.17  1  0
2010-05-01 06:00:00 201005071800  2.20 202.54  1  0
2010-05-01 06:00:00 201005072100  1.81 195.49  1  0
2010-05-01 06:00:00 201005080000  1.64 218.71  1  0
2010-05-01 06:00:00 201005080300  2.44 233.86  1  0
2010-05-01 06:00:00 201005080600  0.96 194.43  1  0
2010-05-01 06:00:00 201005080900  1.76 138.89  1  0
2010-05-01 06:00:00 201005081200  2.79 146.98  1  0
2010-05-01 06:00:00 201005081500  3.45 226.90  1  0
2010-05-01 06:00:00 201005081800  2.56 263.20  1  0
2010-05-01 12:00:00 201005011200  2.56 148.69  1  0
2010-05-01 12:00:00 201005011500  2.54 172.28  1  0
2010-05-01 12:00:00 201005011800  1.78 195.38  1  0
2010-05-01 12:00:00 201005012100  1.23 259.67  1  0
2010-05-01 12:00:00 201005020000  1.04 237.58  1  0
2010-05-01 12:00:00 201005020300  1.75 265.84  1  0 

1 个答案:

答案 0 :(得分:1)

xts对象的数据部分需要是一个矩阵。矩阵需要具有相同原子模式的所有元素:"数字","字符","逻辑"中的一个和仅一个。时间索引需要是可以订购的东西。我不知道你是如何获得索引不变的xts对象的。那不可能。

您似乎选择了错误的列来转换为时间索引。你真正想要的(假设你的目标是创建一个xts对象)是重新开始并将strptime转换应用到你现在看到的" V2"。