简体   繁体   English

从xts 0.9.7更新到0.10.0时xts转换失败

[英]Xts conversion fails on update from xts 0.9.7 to 0.10.0

Dataframe to xts conversion fails on update from xts 0.9.7 to 0.10.0. 从xts 0.9.7更新到0.10.0时,数据帧到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"

Guess xts 0.10.0 is not a finished build. Guess xts 0.10.0尚未完成。 Yet I updated to 0.10.0 as quantstrat package requires blotter package, which requires xts 0.10.0. 但是我更新到0.10.0,因为quantstrat程序包需要blotter程序包,这需要xts 0.10.0。 I needed this to turn a tick data dataframe into an xts object, to run a quantstrat strategy on it (requires xts objects). 我需要这样做,以将刻度数据数据帧转换为xts对象,在其上运行quantstrat策略(需要xts对象)。

This is a problem with your R session, not xts. 这是您的R会话而不是xts的问题。 I'm going to assume you're running RStudio on Windows, where packages are not correctly updated if any R session is currently using the package when you attempt to update. 我将假设您在Windows上运行RStudio,如果您在尝试更新时任何R会话当前正在使用软件包,则软件包不会正确更新。

The solution is to close all your running R sessions, and then install xts from GitHub. 解决方案是关闭所有正在运行的R会话,然后从GitHub安装xts。

Once you do that, you will also need to change your call to as.xts , because xts objects do not like POSIXlt indexes (because they are a list of time components, not number of seconds from the epoch, like POSIXct ). 完成此操作后,您还需要将调用更改为as.xts ,因为xts对象不喜欢POSIXlt索引(因为它们是时间分量的列表,而不是像POSIXct那样从纪元开始的POSIXct )。

R> DFX <- as.xts(DFX[, -1], order.by = DFX$DateTime)
Error in is.finite(order.by) : 
  default method not implemented for type 'list'

I'll open an issue to fix the error. 我将解决一个问题。 It should be as simple as converting the POSIXlt object to POSIXct inside the as.xts call. 它应该是作为转换为简单POSIXlt对象POSIXctas.xts调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM