2012-08-24 30 views
5

請,把這個數據結構轉換爲R,以再現我的例子:爲沒有適用的方法的時間< - '施加到類的對象「C(‘XTS’,‘動物園’)」

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")的DATAS,但我不明白爲什麼它會以這種格式讀取那些數據,我怎樣才能將它強制轉換爲一個簡單的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<- 

根據錯誤messagge,我想安裝timeSeriestime<-當從掩蓋的問題來我真的不知道它是什麼意思,以及如何處理。

+0

已裝入包'xts'? – Pop

+0

當然我有:) 我剛剛爲我的示例代碼添加了另一個命令行,以便加載'quantmod'並加載'xts'。 – user1621969

+0

考慮到'class(as.xts(dX))'仍然會返回''xts「」zoo「對象,而我想省略'zoo'組件。 – user1621969

回答

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) 
+0

謝謝你,羅蘭。請假設我**必須**加載'timeSeries':我該如何處理這個問題? – user1621969

+0

分離並重新加載。 – Roland

+0

是的!還有什麼? :) 非常感謝您 – user1621969

相關問題