Zoo / xts - can't do math on 1-cell subsets? R freezes

I am using the latest version of R / xts / zoo on Windows: R 2.15, xts 0.8-6, zoo 1.7-7

I see the following bizarre behavior, which was not in previous versions:

library(xts)
data(sample_matrix)
sample.xts <- as.xts(sample_matrix)

sample.xts[1, 2] - sample.xts[2,2]     # results in numeric(0)?!?!?!
(sample.xts[ 1, 2] - sample.xts[2,2])/sample.xts[3,1]  # if I run this twice R locks up

Here I have a subset of an XTS object for one cell. Subtraction no longer works. In addition, division causes R to completely block.

Does anyone else see this? Is this a known mistake or am I missing something? I can reproduce this on two machines.

Session Information (multiple packages deleted as confidential):

R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

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

attached base packages:
[1] parallel  stats     graphics  utils     datasets  grDevices methods   base     
+5
source share
1 answer

xts/zoo . . coredata , , .

coredata(sample.xts[1,2]) - coredata(sample.xts[2,2])

, , , zoo/xts xts. , ( ) .

(sample.xts[1,2] - sample.xts[1,3]) / sample.xts[1,4]
(sample.xts[2,2] - sample.xts[1:2,3]) / sample.xts[2:3,4]
+2

All Articles