0

我想用微秒定时索引解析 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"

我尝试了 options(digits.secs=6) 但没有用。

4

1 回答 1

3

如果您可以从 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
于 2010-11-28T05:39:29.267 回答