日期和時間作爲索引I具有以下文件read.zoo與R中
"Index" "time" "open" "high" "low" "close" "numEvents" "volume"
2013-01-09 14:30:00 "2013-01-09T14:30:00.000" "110.8500" "110.8500" "110.8000" "110.8000" " 57" "32059"
2013-01-09 14:31:00 "2013-01-09T14:31:00.000" "110.7950" "110.8140" "110.7950" "110.8140" " 2" " 1088"
2013-01-09 14:32:00 "2013-01-09T14:32:00.000" "110.8290" "110.8300" "110.8290" "110.8299" " 5" " 967"
2013-01-09 14:33:00 "2013-01-09T14:33:00.000" "110.8268" "110.8400" "110.8268" "110.8360" " 8" " 2834"
2013-01-09 14:34:00 "2013-01-09T14:34:00.000" "110.8400" "110.8400" "110.8200" "110.8200" " 33" " 6400"
欲讀取該文件到一個動物園(或XTS)在R.對象時,此文件被創建爲XTS對象並使用write.zoo(as.zoo(xts_object), path, sep = "\t")
保存,現在我正在嘗試使用zoo_object <- read.zoo(path, sep = "\t", header=TRUE, format="%Y-%m-%d %H:%M:%S")
來讀取它。不過,我得到以下警告
Warning message:
In zoo(rval3, ix) :
some methods for 「zoo」 objects do not work if the index entries in ‘order.by’ are not unique
當我鍵入zoo_object
到控制檯,以顯示其內容,我得到:
time open high low close numEvents volume
2013-01-09 2013-01-09T14:30:00.000 110.8500 110.850 110.8000 110.8000 57 32059
2013-01-09 2013-01-09T14:31:00.000 110.7950 110.814 110.7950 110.8140 2 1088
2013-01-09 2013-01-09T14:32:00.000 110.8290 110.830 110.8290 110.8299 5 967
2013-01-09 2013-01-09T14:33:00.000 110.8268 110.840 110.8268 110.8360 8 2834
2013-01-09 2013-01-09T14:34:00.000 110.8400 110.840 110.8200 110.8200 33 6400
在這裏你可以看到的時間不包括在該行的索引。我假設我可以將時間字段轉換爲索引並修復我的問題,但是我也假定我在閱讀這個文件時(或者可能寫了)做了錯誤的事情,但是整天搜索後我不知道是什麼。誰能提供任何見解?
dput(zoo_object)
後讀取
dput(zoo_object)
structure(c("2013-01-09T14:30:00.000", "2013-01-09T14:31:00.000",
"2013-01-09T14:32:00.000", "2013-01-09T14:33:00.000", "2013-01-09T14:34:00.000",
"110.8500", "110.7950", "110.8290", "110.8268", "110.8400", "110.850",
"110.814", "110.830", "110.840", "110.840", "110.8000", "110.7950",
"110.8290", "110.8268", "110.8200", "110.8000", "110.8140", "110.8299",
"110.8360", "110.8200", "57", " 2", " 5", " 8", "33", "32059",
" 1088", " 967", " 2834", " 6400"), .Dim = c(5L, 7L), .Dimnames = list(
NULL, c("time", "open", "high", "low", "close", "numEvents",
"volume")), index = structure(c(15714, 15714, 15714, 15714,
15714), class = "Date"), class = "zoo")
不'read.zoo'有多列值的'index.column'參數嗎?從控制檯測試中構建動物園對象太多了,所以無數次:爲什麼人們不會學習使用'dput'來發布示例? –
對不起,我是R新手,並試圖在飛行中學習。我不知道dput會有用。另外,我的問題是關於從文件到動物園對象。當我將它讀入計算機時,我已經錯過了時間。我也不確定'index.column'是什麼,但我現在要去查看它。 – MarkB42