Xts, Zoo Error: "number of items to replace not multiple of replacement length"
Brian, thanks for your email. Sorry for not providing an reproducible example. But your guess was already spot on. The error was caused by NA's in the data. Once I've taken them out it works fine. Thanks again!! Wolfgang Wu ----- Urspr?ngliche Mail ---- Von: Brian G. Peterson <brian at braverock.com> An: Wob Wu <wobwu22 at yahoo.de> CC: R-SIG-Finance at stat.math.ethz.ch Gesendet: Dienstag, den 9. M?rz 2010, 14:27:55 Uhr Betreff: Re: [R-SIG-Finance] Xts, Zoo Error: "number of items to replace not multiple of replacement length" You haven't provided a reproducible example, per the posting guide. This makes it difficult to help you. This error usually results from NA's or a function failing to return. Look at your data, and see if the replaced series has problems. Also, given that this question really has nothing to do with finance (though it does purport to use xts and zoo) it probably belonged on R-Help, where you would likely have also been told to do your homework and provide a reproducible example. - Brian
Wob Wu wrote:
Hello, I am trying to construct a continous price series of future contracts. This is all working well apart from one bit in my code. After spending hours of debugging I still can't find the source of the problem. So any help is highly appreciated!!! Ok, so basically I am trying to replace the log returns on specific days. This works for nearly all contracts that I am converting, apart from a few. And I really can't see what the difference between it is as the code is exactly the same. So the specific code is: returnNorm[expiryDates,] <- returnRoll[expiryDates,]; This however fails with the error: "Error in NextMethod(.Generic) : number of items to replace is not a multiple of replacement length" where class(returnNorm) and class(returnRoll) is "xts" "zoo" class(expiryDates) is "Date" and dim(returnRoll[expiryDates,]) [1] 242 1
dim(returnNorm[expiryDates,])
[1] 242 1
The data basically looks like this:
returnNorm[expiryDates,]
1.Close
1990-01-23 -0.04304175
1990-02-21 -0.02048786
1990-03-21 0.03466198
1990-04-23 0.06052630
1990-05-23 0.02568539
...
returnRoll[expiryDates,]
1.Close
1990-01-23 -0.007839561
1990-02-21 -0.018232046
1990-03-21 0.009564634
1990-04-23 0.013196285
1990-05-23 -0.042100119
...
expiryDates
[1] "1990-01-23" "1990-02-21" "1990-03-21" "1990-04-23" "1990-05-23" ...
______________________________ f?gt ?ber einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.com _______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock __________________________________________________ Do You enden Schutz gegen Massenmails. http://mail.yahoo.com