1

次の形式のデータフレームがあります

           SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2007-01-03   142.25   142.86  140.57    141.37   94807600       125.38
2007-01-04   141.23   142.05  140.61    141.67   69620600       125.65
2007-01-05   141.33   141.40  140.38    140.54   76645300       124.64
2007-01-08   140.82   141.41  140.25    141.19   71655000       125.22
2007-01-09   141.31   141.60  140.40    141.07   75680100       125.11
2007-01-10   140.58   141.57  140.30    141.54   72428000       125.53

ただし、コマンドindex(DATA.FRAME)は日付ではなく整数を返します。整数の代わりに日付のリストを取得するには、どの関数を使用すればよいですか?

編集:

dput(DATA.FRAME) の出力は

structure(list(SPY.Open = c(142.25, 141.23, 141.33, 140.82, 141.31, 
140.58), SPY.High = c(142.86, 142.05, 141.4, 141.41, 141.6, 141.57
), SPY.Low = c(140.57, 140.61, 140.38, 140.25, 140.4, 140.3), 
    SPY.Close = c(141.37, 141.67, 140.54, 141.19, 141.07, 141.54
    ), SPY.Volume = c(94807600, 69620600, 76645300, 71655000, 
    75680100, 72428000), SPY.Adjusted = c(125.38, 125.65, 124.64, 
    125.22, 125.11, 125.53)), .Names = c("SPY.Open", "SPY.High", 
"SPY.Low", "SPY.Close", "SPY.Volume", "SPY.Adjusted"), row.names = c("2007-01-03", 
"2007-01-04", "2007-01-05", "2007-01-08", "2007-01-09", "2007-01-10"
), class = "data.frame")
4

2 に答える 2

2
rownames(DATA.FRAME) #results in character vector
#[1] "2007-01-03" "2007-01-04" "2007-01-05" "2007-01-08" "2007-01-09" "2007-01-10"

as.Date(rownames(DATA.FRAME)) #convert to date
于 2012-10-19T20:19:37.373 に答える
2

I'm not familiar with the command index in R. It looks like the dates are stored as the rownames of your data frame.

I would try:

as.Date(rownames(DataFrameName))

Alternatively, you can turn integers into dates in R. I forget exactly how, but basically you just need one conversation factor (say 15344 = Oct. 9th 2007 or something) - it should be in ?as.Date or ?as.POSIXct

于 2012-10-19T20:19:38.153 に答える