如何使用 quantmod 包从 R 中的 data.frame 中提取行索引
how to extract row index from data.frame in R with quantmod package
使用quantmod包,我正在拉取股票数据,如下
library(quantmod)
getSymbols('F')
head(F)
给出输出
F.Open F.High F.Low F.Close F.Volume
2007-01-03 7.56 7.67 7.44 7.51 78671500
2007-01-04 7.56 7.72 7.43 7.70 63545800
2007-01-05 7.72 7.75 7.57 7.62 40563800
2007-01-08 7.63 7.75 7.62 7.73 48941200
2007-01-09 7.75 7.86 7.73 7.79 56732500
2007-01-10 7.79 7.79 7.67 7.73 42398600
# and an unimportant(here) warning regarding download length
我希望能够在此处提取明显的日期列,并将数据作为 data.frame 处理,通常我会尝试查找列名并提取该列,但日期是未包含在列中!
它不是 data.frame,它是 xts。如果您想将其作为 data.frame 进行操作并获取日期(它们以行名的形式出现),请尝试:
df <- data.frame(F)
row.names(df)
你可以试试
dates <- index(F)
quantmod 包以 xts 格式提取数据。将 xts 时间序列转换为数据帧可能并不总是可取的。
使用quantmod包,我正在拉取股票数据,如下
library(quantmod)
getSymbols('F')
head(F)
给出输出
F.Open F.High F.Low F.Close F.Volume
2007-01-03 7.56 7.67 7.44 7.51 78671500
2007-01-04 7.56 7.72 7.43 7.70 63545800
2007-01-05 7.72 7.75 7.57 7.62 40563800
2007-01-08 7.63 7.75 7.62 7.73 48941200
2007-01-09 7.75 7.86 7.73 7.79 56732500
2007-01-10 7.79 7.79 7.67 7.73 42398600
# and an unimportant(here) warning regarding download length
我希望能够在此处提取明显的日期列,并将数据作为 data.frame 处理,通常我会尝试查找列名并提取该列,但日期是未包含在列中!
它不是 data.frame,它是 xts。如果您想将其作为 data.frame 进行操作并获取日期(它们以行名的形式出现),请尝试:
df <- data.frame(F)
row.names(df)
你可以试试
dates <- index(F)
quantmod 包以 xts 格式提取数据。将 xts 时间序列转换为数据帧可能并不总是可取的。