R使用quantmod获取行名日期 [英] R obtaining rownames date using quantmod

查看:55
本文介绍了R使用quantmod获取行名日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 quantmod 并从雅虎收集数据.我正在尝试获取行名中的日期.但是我只是得到 NULL.

Using quantmod and collecting data from Yahoo. I am trying to get the dates that are in rownames. However I am just getting NULL.

library("quantmod")
sp500 <- new.env()

getSymbols("^GSPC", env = sp500, src = "yahoo",
           from = as.Date("2008-01-04"),  to = Sys.Date())
GSPC <- get("GSPC", envir = sp500)
date1 <- rownames(GSPC)

date1
> NULL

如果您能帮助我将行名日期放入向量中,我将不胜感激.

I would be grateful for your help into getting the rowname dates into a vector.

推荐答案

您需要使用 index 功能.xts 对象与普通的 data.frame 不同,它有自己的处理维度名称的方式.

You need to use the index function. The xts object isn't the same as a normal data.frame, and has its own way of handling dimension names.

# Return all dates
index(GSPC)

这篇关于R使用quantmod获取行名日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆