从xts 0.9.7到0.10.0更新时,Dataframe到xts转换失败。
#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包,这需要xts0.10.0。我需要这样做才能将滴答数据数据转换为xts对象,并在其上运行quantstrat策略(需要xts对象)。
发布于 2017-06-24 14:10:40
这是R会话的问题,而不是xts。我将假设您在Windows上运行RStudio,如果在尝试更新时有任何R会话正在使用该包,则将无法正确更新包。
解决方案是关闭所有正在运行的R会话,然后从GitHub安装xts。
一旦这样做,您还需要更改对as.xts的调用,因为xts对象不喜欢POSIXlt索引(因为它们是时间组件的列表,而不是与时代相距的秒数,比如POSIXct)。
R> DFX <- as.xts(DFX[, -1], order.by = DFX$DateTime)
Error in is.finite(order.by) :
default method not implemented for type 'list'我将打开一个问题来修复错误。它应该与在POSIXlt调用中将POSIXct对象转换为as.xts对象一样简单。
https://stackoverflow.com/questions/44732011
复制相似问题