zoo/xts - 不能对 1-cell 子集进行数学运算?R 挂起 [英] zoo/xts - can't do math on 1-cell subsets? R hangs
问题描述
我在 Windows 上使用最新版本的 R/xts/zoo:R 2.15、xts 0.8-6、zoo 1.7-7
I'm using latest version of R/xts/zoo on Windows: R 2.15, xts 0.8-6, zoo 1.7-7
我看到了以下奇怪的行为,这在以前的版本中并非如此:
I'm seeing the following bizarre behavior, which was not the case with prior 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
在这里,我将 XTS 对象子集化为单个单元格.减法不再有效.此外,除法导致 R 完全锁定.
Here I have subset an XTS object to a single cell. Subtraction no longer works. Also, division causes R to completely lock up.
还有人看到这个吗?这是一个已知的错误还是我遗漏了什么?我可以在两台机器上重现这个.
Does anyone else see this? Is this a known bug or am I missing something? I can reproduce this on two machines.
会话信息(一些包作为机密删除):
Session Info (a few 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
推荐答案
您永远无法减去索引不重叠的 xts/zoo 对象.算术运算总是在执行运算之前合并.您需要使用 coredata
以便您编写的减法提供您期望的结果.
You never could subtract xts/zoo objects with non-overlapping indices. Arithmetic operations always merge before performing the operation. You need to use coredata
in order for the subtraction you've written to provide the result you expect.
coredata(sample.xts[1,2]) - coredata(sample.xts[2,2])
我可以复制第二个问题,但我不确定这应该是解决的高优先级问题,因为它不符合 zoo/xts 习惯用法,并且会导致一个完全空的 xts 对象.如果(某些)索引对齐,一切都很好.
I can replicate the second issue but I'm not sure this should be a high priority to fix, because it doesn't fit the zoo/xts idiom and would result in a completely empty xts object. Everything is fine if (some of) the indices align.
(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]
这篇关于zoo/xts - 不能对 1-cell 子集进行数学运算?R 挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!