将 xts 或 Zoo 时间序列对象的每一行除以固定行
我正在尝试划分一个包含多个时间序列(列;具有公共日期列(索引))的 xts 对象。我想将每列除以其在指定日期的值(例如“2010-09-30”)这是为了在该日期将整个对象的每列值重新调整为 1(如果它是普通矩阵 A 和行)。我想重新设定为就是说 A[6,]
,我可以这样做
t(t(A)/A[6,])
并且可行,但是,尝试操作 xts 对象及其行子集 xts['2010-09-30'] 并不那么容易工作。有人可以指出我正确的方向吗?我意识到这是非常基本的,事实上,如果有更好的方法来调整时间。系列以这种方式使用一个包,我我很高兴采用这种方法。
I am trying to divide an xts object which holds a number of time series (columns; with a common date column (index). I want to divide each column by its value at a specified date (say '2010-09-30'). This is so as to re-scale the entire object with values of 1 in each column at that date (a common re-basing task). Had it been an ordinary matrix, A
, and the row I wanted to rebase to was say A[6,]
, I could just do
t(t(A)/A[6,])
and that works. But, trying to manipulate the xts object and its row subset xts['2010-09-30']
doesn't work as easily. Could someone please point me in the right direction. I realise this is very basic and I should have found the answer on my own. In fact, if there is a better method in general for rebasing time series in this manner using a package, I am happy to adopt that approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
xts 和 Zoo 对象在操作之前按索引对齐。如果您想将整个对象除以单行的值,则必须使用 coredata(也可能是 drop)将值获取到原子向量(使用只有一个元素)。
例如:
xts and zoo objects are aligned by index before operations. If you want to divide an entire object by a value at a single row, you have to use
coredata
(and maybedrop
) to get the value to an atomic vector (with only one element).For example: