R - zoo/XTS 微秒读取问题



>数据看起来像

           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 问题2. 在 R 中调用 strptime 时的毫秒难题3. 如何在R中解析毫秒?

但是,这无济于事。任何建议

您希望

索引是时间类,例如 POSIXctPOSIXlt 。 另外,你的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

最新更新