相关疑难解决方法(0)

R:index()或index.xts()改变时间序列的日期值,为什么?

我想从使用getSymbols获得的时间序列中提取日期,但是当我使用index/index.xts函数时,返回的日期似乎是提前一天.我无法理解为什么在以下代码中发生此行为.

但是,预期的行为是获取与原始时间序列中的对象相对应的Date对象列表.

以下是代码,请注意时间序列SPY的最后日期是2012年8月24日,但索引(SPY)调用的最后一个值是2012年8月23日:

getSymbols("SPY")

tail(SPY)

    SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2012-08-17   142.23   142.30  141.86    142.18   90813700       142.18
2012-08-20   141.98   142.22  141.59    142.19   78255700       142.19
2012-08-21   142.54   143.09  141.45    141.76  105581100       141.76
2012-08-22   141.40   142.05  141.07    141.82  132999200       141.82
2012-08-23   141.47   141.48  140.44    140.66  111406800       140.66
2012-08-24   140.31   141.83  140.22    141.51   99431500       141.51 

tail(index(SPY))

[1] "2012-08-16" "2012-08-19" "2012-08-20" "2012-08-21" "2012-08-22" "2012-08-23"

tail(index.xts(SPY))

[1] "2012-08-16" "2012-08-19" "2012-08-20" "2012-08-21" "2012-08-22" "2012-08-23"
Run Code Online (Sandbox Code Playgroud)

感谢所有能回复我帖子的人.

有关会话的其他信息

>sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale: …
Run Code Online (Sandbox Code Playgroud)

indexing r date time-series xts

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

date ×1

indexing ×1

r ×1

time-series ×1

xts ×1