没有适用于类“c('xts', 'zoo')”对象的“time < -”方法。

6
请将以下数据结构放入R中以重现我的示例:
dX <- structure(c(3272.1, 3271.48, 3281.03, 3267.08, 3260.65, NA, 1616.3, 
1620.1, 1639.9, 1637.4, 1669.6, 1662.2, 528.385, 529.268, 531.022, 
532.424, NA, NA), .indexTZ = "", class = c("xts", "zoo"), .indexCLASS = c("POSIXct", 
"POSIXt"), tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1345147200, 
1345406400, 1345492800, 1345579200, 1345665600, 1345752000), tzone = "", tclass = c("POSIXct", 
"POSIXt")), .Dim = c(6L, 3L), .Dimnames = list(NULL, c("M1WO.Index", 
"GC1.COMB.Comdty", "JGAGGUSD.Index")))

现在尝试使用这段代码:
library(PerformanceAnalytics)
library(quantmod)
library(timeSeries)
charts.PerformanceSummary(R = dX)

并且出现了以下错误:

Error in UseMethod("time<-") :
  no applicable method for 'time<-' applied to an object of class "c('xts', 'zoo')"

我猜这个问题与数据的 class = c("xts, "zoo") 有关,但我不明白为什么它以那种格式读取这些数据,如何将其强制转换为一个简单的 xts 对象。

我该如何解决这个问题?

我的系统:

R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] timeSeries_2160.94           timeDate_2160.95            
 [3] quantmod_0.3-17              TTR_0.21-1                  
 [5] Defaults_1.1-1               PerformanceAnalytics_1.0.4.4
 [7] xts_0.8-6                    zoo_1.7-7                   
 [9] rcom_2.2-5                   rscproxy_2.0-5              

loaded via a namespace (and not attached):
[1] fBasics_2160.81  fGarch_2110.80.1 grid_2.15.1      lattice_0.20-6  
[5] MASS_7.3-18      stabledist_0.6-4 tools_2.15.1  

当我加载软件包时,我会得到以下信息:

Loading required package: zoo

Attaching package: ‘zoo’

The following object(s) are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: timeDate

Attaching package: ‘timeDate’

The following object(s) are masked from ‘package:PerformanceAnalytics’:

    kurtosis, skewness

Attaching package: ‘timeSeries’

The following object(s) are masked from ‘package:zoo’:

    time<-

根据错误信息,我猜想问题出在连接 timeSeriestime<-时被 package:zoo 掩盖了,对此我并不清楚其含义以及如何处理。


你是否已经加载了xts包? - Pop
当然,我已经做了 :)我刚刚在我的示例代码中添加了另一个命令行,以加载quantmod并加载xts - user1621969
你的代码没有出现错误。sessionInfo() 的输出是什么? - Roland
这段内容太长了,无法在此处附加。您感兴趣的领域是什么?`R版本2.15.1(2012-06-22) 平台:i386-pc-mingw32 / i386(32位)语言环境: [1] LC_COLLATE = English_United States.1252 [2] LC_CTYPE = English_United States.1252 [3] LC_MONETARY = English_United States.1252 [4] LC_NUMERIC = C [5] LC_TIME = English_United States.1252` - user1621969
loaded via a namespace (and not attached): [1] fBasics_2160.81 fGarch_2110.80.1 grid_2.15.1 lattice_0.20-6 [5] MASS_7.3-18 stabledist_0.6-4 tools_2.15.1 - user1621969
显示剩余4条评论
1个回答

10

问题出在 timeSeries 包上。载入该包时会产生以下警告:

Attaching package: ‘timeSeries’

The following object(s) are masked from ‘package:zoo’:

    time<-

您可以将包从charts.PerformanceSummary中分离出来再重新加载:

detach('package:timeSeries')
detach('package:timeDate') # since it masks statistical functions
charts.PerformanceSummary(R = dX)
library(timeSeries)

谢谢,Roland。请假设我必须加载timeSeries:我该如何处理这个问题? - user1621969
没错!还有什么需要吗? :) 非常感谢。 - user1621969
@user1621969,你可以对你的PerformanceAnalytics版本进行修补。将chart.TimeSeries.R的第237行修改为rownames = as.Date(xts:::time.xts(y))。然后重新构建并安装即可。 - GSee
@user1621969:你也可以先加载timeSeries,然后再加载PerformanceAnalytics。这将确保timeSeries和timeDate在搜索路径中比xts/zoo更靠后,因此xts/zoo的time<-方法将首先被找到。 - Joshua Ulrich
感谢Brian快速应用补丁。您可以按照这里的说明来检出、构建和安装最新版本的PerformanceAnalytics。 - GSee

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接