问题
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