如何在 R 中的 quantmod 包中打印股权的日期?
我想从 R 中的 quanatmod 包加载 Tesla 股票 5 年的历史记录。这样做我有:
tsla <- quantmod::getSymbols("TSLA", from = base::as.Date("2017-01-01"), to = base::as.Date("2022-01-31"), auto.assign = F)
tsla = as_tibble(tsla)
head(tsla)
但我还想要一个包含每个索引上的日期的列。如何在不添加日期的情况下完成此操作,因为这些价格对应于具体日期。
I want to load the 5 years history of Tesla equity from quanatmod package in R.Doing so I have :
tsla <- quantmod::getSymbols("TSLA", from = base::as.Date("2017-01-01"), to = base::as.Date("2022-01-31"), auto.assign = F)
tsla = as_tibble(tsla)
head(tsla)
But I also want a column with the dates on each index.How can this be done without just adding dates, because these prices correspond to specific dates .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从
xts
输出转换为data.frame
后,我们可以使用rownames_to_column
。-output
或者可以用
fortify.zoo
来完成We may use
rownames_to_column
after converting todata.frame
from thexts
output.-output
Or it can be done with
fortify.zoo
只需打印 TSLA xts 对象即可。 (
fortify.zoo(TSLA)
将其转换为第一列中带有索引的数据框,但只是打印它并不真正需要。)给出:
Just print the TSLA xts object. (
fortify.zoo(TSLA)
converts it to a data frame with the index in the first column but isn't really needed for simply printing it.)giving: