2011-11-21 75 views
-1

我是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)` 

我有被在3天的跨度,每6小時爲接下來的八天更新一次數據。 我已經編碼如下:

執行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:0 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:0 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 
+0

因此:第三列是由YEARMONTHDAYHOURMINUTE組成的字符串?如果是這樣,使用字符串函數來提取HOURMINUTE部分可能是最簡單的。或者你可以通過'lubridate'包查看一些有用的功能。 –

+2

這裏沒有問題。你想做什麼,這有什麼問題? –

+0

不知道你到底想要什麼,但也許你可以在這個Stackexchange問​​題中找到一些信息:[http://stats.stackexchange.com/questions/12980/subset-data-by-mon-th-in-r/12992# 12992](http://stats.stackexchange.com/questions/12980/subset-data-by-month-in-r/12992#12992) – pacomet

回答

1

xts對象的數據部分需要是矩陣。矩陣需要具有相同原子模式的所有元素:「數字」,「字符」,「邏輯」中的一個並且只有一個。時間索引需要是可以訂購的東西。我不知道你是如何得到一個索引不變的xts對象的。這應該是不可能的。

您似乎選擇了錯誤的列轉換爲時間索引。您真正想要的(假設您的目標是創建一個xts對象)是重新開始並將strptime轉換應用於您現在看到的「V2」。