【问题标题】:Display time index in R xts以 R xts 显示时间索引
【发布时间】:2011-05-16 18:36:24
【问题描述】:

我想用微秒定时索引解析 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) 但没有成功。

【问题讨论】:

    标签: r xts


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      • 1970-01-01
      相关资源
      最近更新 更多