【问题标题】:How to load a 4-column table into an xts object? [duplicate]如何将 4 列表加载到 xts 对象中? [复制]
【发布时间】:2014-03-01 09:12:18
【问题描述】:

我想开始学习如何使用 xts 包,但我很难加载我的数据。

文件大约 6MB,看起来像这样:

Date,Time,Price,Size
02/18/2014,05:06:13,49.6,200
02/18/2014,05:06:13,49.6,200
02/18/2014,05:06:13,49.6,200
02/18/2014,05:06:14,49.6,200
02/18/2014,05:06:14,49.6,193
02/18/2014,05:44:41,49.62,100
02/18/2014,06:26:36,49.52,100
02/18/2014,06:26:36,49.52,500
02/18/2014,07:09:29,49.6,100
02/18/2014,07:56:40,49.56,300
02/18/2014,07:56:40,49.55,400
02/18/2014,07:56:41,49.54,200
02/18/2014,07:56:43,49.55,100
02/18/2014,07:56:43,49.55,100
02/18/2014,07:56:50,49.55,100
02/18/2014,07:57:12,49.53,100
02/18/2014,07:57:12,49.51,2200
02/18/2014,07:57:12,49.51,100
02/18/2014,07:57:12,49.5,200

这是我尝试的代码行和我得到的错误:

data1<-as.xts(read.zoo("EKSO_0.txt",header = T,sep=",",format="%m/%d/%Y"))

我得到的错误:

Warning message:
In zoo(rval3, ix) :
some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not   unique

如何加载“时间”列?

感谢您的帮助。

【问题讨论】:

  • 我想你会想要加载第 1 列和第 2 列来创建日期时间索引。那么您将不会收到该警告。

标签: r xts


【解决方案1】:

我想这就是你要找的。它来自zoo vignette 中的示例 4。您仍然会收到警告,因为您仍然有重复的日期、时间组合

library(zoo)
library(chron)

f <- function(d, t) as.chron(paste(as.Date(chron(d)), t))
read.zoo("EKSO_0.txt", header = TRUE, sep = ",", index.column = 1:2, FUN = f)

##                     Price Size
## (02/18/14 05:06:13) 49.60  200
## (02/18/14 05:06:13) 49.60  200
## (02/18/14 05:06:13) 49.60  200
## (02/18/14 05:06:14) 49.60  200
## (02/18/14 05:06:14) 49.60  193
## (02/18/14 05:44:41) 49.62  100
## (02/18/14 06:26:36) 49.52  100
## (02/18/14 06:26:36) 49.52  500
## (02/18/14 07:09:29) 49.60  100
## (02/18/14 07:56:40) 49.56  300
## (02/18/14 07:56:40) 49.55  400
## (02/18/14 07:56:41) 49.54  200
## (02/18/14 07:56:43) 49.55  100
## (02/18/14 07:56:43) 49.55  100
## (02/18/14 07:56:50) 49.55  100
## (02/18/14 07:57:12) 49.53  100
## (02/18/14 07:57:12) 49.51 2200
## (02/18/14 07:57:12) 49.51  100
## (02/18/14 07:57:12) 49.50  200
## Warning message:
## In zoo(rval3, ix) :
##   some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多