Search code examples
rquantmod

how to extract row index from data.frame in R with quantmod package


using the quantmod package, I am pulling stock data, as below

library(quantmod)
getSymbols('F')
head(F)

which gives the output

           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

I want to be able to extract the obvious date column here, and work with the data as a data.frame, usually I would try to look up the column names and pull that column, but the dates are not included in a column!


Solution

  • It is not a data.frame, it is an xts. If you want to manipulate it as a data.frame and get the dates (they come over as rownames) try:

       df <- data.frame(F)
       row.names(df)