2014-05-20 3 views
2

XTS 개체가 있는데 특정 날짜의 데이터를 새 집합으로 바꾸려고합니다. 나는 그들이 동일하고 누락 된 데이터가 아님에도 불구하고 대체 길이에 관한 문제를 계속 다루고있다. 어떤 아이디어? XTS 대체 오류 NextMethod (.Generic) : 대체 할 항목 수

나는 내 문제를 보여주기 위해 더미 예제를 만들어 :

경고가 아닌 오류의
R> test1 = xts(cbind(trade_level = 1, t2 = 3),order.by=as.Date("1991-01-02")) 
R> test2 = xts(cbind(trade_level = 5, t2 = .053),order.by=as.Date("1991-01-02")) 
R> first_day = "1991-01-02" 
R> test1[first_day] = test2 
Warning message: 
In NextMethod(.Generic) : 
    number of items to replace is not a multiple of replacement length 
R> sessionInfo() 
R version 3.0.1 (2013-05-16) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 

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

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

other attached packages: 
[1] reshape2_1.2.2 xts_0.9-7  zoo_1.7-10  ggplot2_0.9.3.1 

loaded via a namespace (and not attached): 
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.4  grid_3.0.1   
[5] gtable_0.1.2  labeling_0.2  lattice_0.20-23 MASS_7.3-29  
[9] munsell_0.4.2  plyr_1.8   proto_0.3-10  RColorBrewer_1.0-5 
[13] scales_0.2.3  stringr_0.6.2  tools_3.0.1  

답변

1

. 그리고 무엇이 잘못 되었는가에 대한 힌트를 제공합니다 ... 쉼표를 추가하여 모든 열을 대체하도록 지정해야합니다.

test1 = xts(cbind(trade_level = 1, t2 = 3),order.by=as.Date("1991-01-02")) 
test2 = xts(cbind(trade_level = 5, t2 = .053),order.by=as.Date("1991-01-02")) 
first_day = "1991-01-02" 
test1[first_day,] = test2 

그러나 XTS를 비난하지 않는다,이 행렬 클래스가 어떻게 작동 :

test1 = xts(cbind(trade_level = 1, t2 = 3),order.by=as.Date("1991-01-02")) 
test2 = xts(cbind(trade_level = 5, t2 = .053),order.by=as.Date("1991-01-02")) 
m1 <- as.matrix(test1) 
m2 <- as.matrix(test2) 
m1[1] <- m2 # warning 
m1[1,] <- m2 # works