题
我想用微秒定时索引解析CSV。因此,我编写了这样的代码:
t<-read.zoo("test", index.column = 1, sep=",",header=TRUE, format="%Y-%m-%d %H:%M:%OS")
t.xts<-as.xts(t)
之后,我尝试显示此内容,但看不到索引上的时间信息。
> 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"
我尝试了选项(digits.secs = 6),但无效。
解决方案
如果您可以从CSV文件中提供几行,这将有所帮助。环境 options(digits.secs=6)
为我工作。您也可以尝试手动设置格式 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
不隶属于 StackOverflow