在 R xts 中显示时间索引

发布于 2024-10-04 18:04:38 字数 506 浏览 3 评论 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) 但没有成功。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱了心跳 2024-10-11 18:04:38

如果您可以提供 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文