2017-06-24 3 views
1

Konvertierung von Dataframe in xts schlägt beim Aktualisieren von xts 0.9.7 auf 0.10.0 fehl.XTS-Konvertierung schlägt bei Aktualisierung von xts 0.9.7 auf 0.10.0 fehl

#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" 

Raten xts 0.10.0 ist kein fertiges Build. Aber ich aktualisiert auf 0.10.0 als quantstrat Paket erfordert Löschpapier Paket, das XTS 0.10.0 erfordert. Ich brauchte dies, um einen Tickdaten-Datenrahmen in ein xts-Objekt umzuwandeln, um eine Quantstrat-Strategie darauf auszuführen (erfordert xts-Objekte).

Antwort

3

Dies ist ein Problem mit Ihrer R-Sitzung, nicht XTS. Ich gehe davon aus, dass Sie RStudio unter Windows ausführen, wo Pakete nicht korrekt aktualisiert werden, wenn eine R-Sitzung das Paket gerade verwendet, wenn Sie versuchen, es zu aktualisieren.

Die Lösung besteht darin, alle laufenden R-Sitzungen zu schließen und dann xts von GitHub zu installieren.

Sobald Sie das tun, werden Sie auch Ihren Anruf as.xts, weil xts Objekte POSIXlt Indizes nicht wie ändern müssen (weil sie eine Liste von Zeitkomponenten sind, nicht wie viele Sekunden aus der Epoche, wie POSIXct).

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

Ich werde ein Problem öffnen, um den Fehler zu beheben. Es sollte so einfach sein wie das Konvertieren des POSIXlt Objekts in POSIXct innerhalb des as.xts Aufrufs.

+0

Die Konvertierung von 'POSIXlt' nach' POSIXct' löste das Problem. Es macht Sinn. Interessant, es war kein Problem auf xts 0.9.7. Danke, Joshua. – Krug

+1

@Gracos: Siehe [Ausgabe # 194] (https://github.com/joshuaulrich/xts/issues/194). Sieht so aus, als wäre es etwas, das ich beim Patchen eines anderen Problems eingeführt habe. –

Verwandte Themen