【问题标题】:zoo/xts microsecond read issuezoo/xts 微秒读取问题
【发布时间】:2012-06-23 13:55:42
【问题描述】:

数据看起来像

           Time  Set1    Set2   
10:19:38.551629 16234   16236   
10:19:41.408010 16234   16236   
10:19:47.264204 16234   16236   

我正在尝试将其加载到动物园中。

orig <- read.zoo("~/sample.txt",sep="",header=TRUE,index.column=1,format="%H:%M:%S.%6f")

Error in read.zoo("~/sample.txt", sep = "", header = TRUE, index.column = 1,  : 
  index has 3 bad entries at data rows: 1 2 3 ...

我已经检查了所有相关的帖子 1.R issue with rounding milliseconds 2.Milliseconds puzzle when calling strptime in R 3.How to parse milliseconds in R?

然而这并没有帮助。 任何建议

【问题讨论】:

  • 请注意,所有这些帖子的答案都使用format = '%H:%M:%OS' 或format = '%H:%M:%OS6'

标签: r time-series xts zoo strptime


【解决方案1】:

您希望索引是一个时间类,例如POSIXct 或POSIXlt。此外,您的 format 论点不太正确。试试这个

read.zoo("~/sample.txt", header = TRUE, format="%H:%M:%OS", FUN=as.POSIXct)

对于提供的示例数据,给出了

read.zoo(text="           Time  Set1    Set2   
10:19:38.551629 16234   16236   
10:19:41.408010 16234   16236   
10:19:47.264204 16234   16236   ", header = TRUE, format="%H:%M:%OS", FUN=as.POSIXct)
#                            Set1  Set2
#2012-06-21 10:19:38.551629 16234 16236
#2012-06-21 10:19:41.408010 16234 16236
#2012-06-21 10:19:47.264204 16234 16236

【讨论】:

  • 请注意,read.zoo(..., tz = "") 或类似但使用 tz="GMT" 会导致 read.zoo 默认为 POSIXct 并指示时区。
  • Set1 Set2 2012-06-22 10:19:38 16234 16236 2012-06-22 10:19:41 16234 16236 2012-06-22 10:19:47 16234 16236。我也设置了options(digits=6),但 read.zoo 中仍然没有微秒时间戳
  • options(digits.secs=6)。运行它,然后你会看到微秒。
  • 感谢 GSee。动物园似乎很强大。
猜你喜欢
  • 1970-01-01
  • 2012-10-08
  • 2011-09-21
  • 2018-07-13
  • 2017-03-28
  • 2018-01-21
  • 2019-02-13
  • 2020-07-09
  • 2011-02-18
相关资源
最近更新 更多