【发布时间】:2015-01-14 22:01:39
【问题描述】:
我有一个名为 Daily_Quotes 的 xts 对象,其中包含股票报价。我正在使用endpoints 来获取我使用getSymbols(来自quantmod 包)检索到的每月股票报价。我注意到endpoints 函数为包含特定月份的最后一个交易日的行创建了一个索引,并将其分配给指定日期范围内的新对象。反正有没有得到本月的第一个交易日?
# My code
Monthly_Quotes <- Daily_Quotes[endpoints(Daily_Quotes,'months')]
我尝试做的是:
# This gave me the next day or 1st day of the next month
# or next row for the object.
endpoints(Daily_Quotes,'months') + 1
# So I applied this and it gave me
# Error in `[.xts`(Daily_Quotes, endpoints(Daily_Quotes, "months") + 1) :
# subscript out of bounds
Monthly_Quotes <- Daily_Quotes[endpoints(Daily_Quotes,'months') + 1]
我该如何解决这个问题?
【问题讨论】:
-
通常最好不要将答案编辑到您的问题中。我们试图将问题和答案分开。如果有人现在阅读您的问题,那么您在问什么就不太清楚了,因为它说“我该如何尝试解决这个问题?”然后是解决方案。
-
@GSee:出于这个原因,我回滚了这些编辑。
-
感谢 Joshua,因为我打算自己编辑它。 @Gsee 将继续这样做。