Display time index in R xts

て烟熏妆下的殇ゞ 提交于 2020-01-17 03:47:09

问题


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"

I tried options(digits.secs=6) but didn't work.


回答1:


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


来源:https://stackoverflow.com/questions/4295407/display-time-index-in-r-xts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!