在 R xts 中显示时间索引 [英] Display time index in R xts
本文介绍了在 R xts 中显示时间索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用微秒定时索引解析 csv.所以,我写了这样的代码:
I want to parse csv with micro-second timed index. So, I wrote code like this:
t<-read.zoo("test", index.column = 1, sep=",",header=TRUE, format="%Y-%m-%d %H:%M:%OS")
t.xts<-as.xts(t)
此后,我尝试显示此内容,但在索引上看不到时间信息.
after then, I tried to display this but I couldn't see time information on the index.
> t.xts[1:10,4]
drate
2010-09-28 " -149"
2010-09-28 " -269"
2010-09-28 " -358"
2010-09-28 " -358"
2010-09-28 " -239"
2010-09-28 " -149"
2010-09-28 " -149"
2010-09-28 " -149"
2010-09-28 " -119"
2010-09-28 " -149"
我尝试了 options(digits.secs=6) 但没有奏效.
I tried options(digits.secs=6) but didn't work.
推荐答案
如果您能提供 CSV 文件中的几行内容,将会有所帮助.设置 options(digits.secs=6)
对我有用.您也可以尝试使用 indexFormat
手动设置格式.
It would help if you could provide a few lines from your CSV file. Setting options(digits.secs=6)
works for me. You could also try manually setting the format with indexFormat
.
> x <- .xts(1:5, 1:5+runif(5))
> x
[,1]
1969-12-31 18:00:01 1
1969-12-31 18:00:02 2
1969-12-31 18:00:03 3
1969-12-31 18:00:04 4
1969-12-31 18:00:05 5
> indexFormat(x) <- "%Y-%m-%d %H:%M:%OS3"
> x
[,1]
1969-12-31 18:00:01.915 1
1969-12-31 18:00:02.002 2
1969-12-31 18:00:03.134 3
1969-12-31 18:00:04.981 4
1969-12-31 18:00:05.204 5
> indexFormat(x) <- "%Y-%m-%d %H:%M:%OS"
> options(digits.secs=6)
> x
[,1]
1969-12-31 18:00:01.914681 1
1969-12-31 18:00:02.001752 2
1969-12-31 18:00:03.134311 3
1969-12-31 18:00:04.981147 4
1969-12-31 18:00:05.204021 5
这篇关于在 R xts 中显示时间索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文