包中有一个fPortfolio名为SPISECTOR.RET. 我希望我的数据框 [ df] 具有与数据框 [ ] 相同的格式 ( global environment) SPISECTOR.RET。我df目前 data.frame是6 obs. of 3 variables. 我想把它values作为timeSeries一个描述Formal Class timeSeries。我在df下面附上了 dput。
library('fPortfolio')
data = SPISECTOR.RET
data(head)
以下是我试图通过更改日期来做的事情。但是发生了错误:Error in xts(df, as.Date(colnames(df), format = "%m/%d/%Y")) : NROW(x) must match length(order.by)
library(xts)
stocks <- xts(df, as.Date(colnames(df), format='%m/%d/%Y'))
输入(df):
structure(list(ACWI = c(10795L, 10763L, 10768L, 10907L, 10761L,
10905L), GLD = c(4811L, 4819L, 4853L, 4899L, 4924L, 4882L), TLT = c(615.88,
615.13, 614.5, 617.38, 619.63, 628.63)), class = "data.frame", row.names = c("09/12/2019",
"10/12/2019", "11/12/2019", "12/12/2019", "13/12/2019", "16/12/2019"
))