There is a dataframe in the fPortfolio package called SPISECTOR.RET. I want my dataframe [df] to have the same format (global environment) as the dataframe [SPISECTOR.RET]. My df is currently a data.frame of 6 obs. of 3 variables. I want it in values as a timeSeries with a description of Formal Class timeSeries. I have dput for df attached below.
library('fPortfolio')
data = SPISECTOR.RET
data(head)
Below is what I tried to do by changing the date. however an error occured: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'))
dput(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"
))