zoo/xts 微秒读取问题 [英] zoo/xts microsecond read issue

查看:24
本文介绍了zoo/xts 微秒读取问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据看起来像

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

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

I am trying to load this into zoo.

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 中解析毫秒?

I have checked all the relevant posts 1. R issue with rounding milliseconds 2. Milliseconds puzzle when calling strptime in R 3. How to parse milliseconds in R?

然而这无济于事.任何建议

However this does not help. Any Suggestions

推荐答案

您希望索引是一个时间类,例如 POSIXctPOSIXlt.此外,您的 format 参数不太正确.试试这个

You want the index to be a time class such as POSIXct or POSIXlt. Also, your format argument wasn't quite right. Try this

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

对于提供的样本数据,给出

Which, for the sample data provided, gives

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

这篇关于zoo/xts 微秒读取问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆