我使用quantmod::getsymbols
功能来检索stock index data for yahoo finance(如图所示,它被称为GDAXI.xts
)
现在我想访问左边的日期,但是此列不在GDAXI文件中。我该如何访问日期?我尝试了不同的方法并且无法解决这个问题,上次当我尝试d1.ts=GDAX[,0]
时它起作用了,但那里不起作用。
有人可以告诉我为什么吗?非常感谢你提前。
Datum=as.Date(GDAXI[,0])
Error in as.Date.default(GDAXI[, 0]) :
do not know how to convert 'GDAXI[, 0]' to class “Date”
Datum=GDAXI[,0]
View(Datum)
Warning in View :
'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Warning in View :
'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Warning message:
In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Datum=as.date(GDAXI[,0])
Error: could not find function "as.date"
In addition: Warning messages:
1: In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
2: In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
3: In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Da.ts=GDAXI[,0]
答案 0 :(得分:0)
我不熟悉R或quantmod,但它看起来像你要做的就是得到行的名称,而不是任何列数据,这可能是你的代码失败的原因,因此它说它不能将GDAXI [,0]解析为Date对象。
如果要在quantmod中获取行的名称,则需要使用索引函数,例如:
# Return all dates
index(GSPC)
您可能还想查看此related question。