dataframe to XTS转换在XTS 0.9.7到0.10.0的更新失败。
#THIS WORKS (uses xts 0.9.7):
library(xts)
DFX <- structure(list(DateTime = structure(list(sec = c(0, 0, 0), min = c(10L, 0L, 5L), hour = c(17L, 18L, 18L), mday = c(24L, 24L, 24L), mon = c(5L, 5L, 5L), year = c(114L, 114L, 114L), wday = c(2L, 2L, 2L), yday = c(174L, 174L, 174L), isdst = c(1L, 1L, 1L), zone = c("EDT", "EDT", "EDT"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_)), .Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst", "zone", "gmtoff"), class = c("POSIXlt", "POSIXt")), Open = c(125.03, 125.34, 125.85)), .Names = c("DateTime", "Open"), class = "data.frame", row.names = 558:560)
DFX <- as.xts(DFX[, -1], order.by = DFX$DateTime)
#THIS DOESN'T WORK (uses xts 0.10.1):
install.packages("devtools")
require(devtools)
install_github("joshuaulrich/xts")
library(xts)
DFX <- structure(list(DateTime = structure(list(sec = c(0, 0, 0), min = c(10L, 0L, 5L), hour = c(17L, 18L, 18L), mday = c(24L, 24L, 24L), mon = c(5L, 5L, 5L), year = c(114L, 114L, 114L), wday = c(2L, 2L, 2L), yday = c(174L, 174L, 174L), isdst = c(1L, 1L, 1L), zone = c("EDT", "EDT", "EDT"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_)), .Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst", "zone", "gmtoff"), class = c("POSIXlt", "POSIXt")), Open = c(125.03, 125.34, 125.85)), .Names = c("DateTime", "Open"), class = "data.frame", row.names = 558:560)
DFX <- as.xts(DFX[, -1], order.by = DFX$DateTime)
#Error message:
#Error in .Call("do_is_ordered", x = x, increasing = as.logical(increasing), :
# "do_is_ordered" not available for .Call() for package "xts"
猜测 XTS 0.10.0不是完成的构建。但是,我将0.10.0更新为 Quantstrat 包需要 blotter 软件包,该软件包需要XTS 0.10.0。我需要此将tick数据框架变成XTS对象,以便在其上运行Quantstrat策略(需要XTS对象(。
这是您的R会议而不是XTS的问题。我将假设您正在Windows上运行rstudio,如果您尝试更新时,如果当前有任何R会话正在使用该软件包,则软件包无法正确更新。
。解决方案是关闭所有运行r会话,然后从github安装XT。
这样做后,您还需要将呼叫更改为as.xts
,因为XTS对象不喜欢POSIXlt
索引(因为它们是时间组件的列表,而不是时期的秒数,例如POSIXct
(。/p>
R> DFX <- as.xts(DFX[, -1], order.by = DFX$DateTime)
Error in is.finite(order.by) :
default method not implemented for type 'list'
我将打开一个问题来解决错误。它应该像将POSIXlt
对象转换为as.xts
呼叫中的POSIXct
一样简单。