0

I've searched a while for a 3D data format, where 1st dim would be timestamp like xts and 2nd two a matrix. There was a solution close enough R - store a matrix into a single dataframe cell but i want to have the xts object instead of data frame. So here it goes:

myDF = data.frame(PnL=I(list()) )
myDF[[1, 'PnL']] <- matrix(rnorm(9), 3, 3,dimnames = list(NULL,c("x1","x2","x3")))
myDF[[2, 'PnL']] <- matrix(rnorm(9), 3, 3,dimnames = list(NULL,c("x1","x2","x3")))
myDF[[3, 'PnL']] <- matrix(rnorm(9), 3, 3,dimnames = list(NULL,c("x1","x2","x3")))

i can nicely access the elements by myDF[[1]], however i want xts style so i convert:

timestamps = as.Date("2016-01-01") + 0:2
ts_array = xts(myDF, order.by = timestamps)

And here the problems start:

> ts_array
Error in coredata.xts(x) : currently unsupported data type
> ts_array[["2016-01-01"]]
NULL

zoo is a bit better, however i still cannot access by timestamp:

> ts_array
           PnL      
2016-01-01 Numeric,9
2016-01-02 Numeric,9
2016-01-03 Numeric,9
> ts_array[["2016-01-01"]]
NULL

Appreciate your ideas :)

Community
  • 1
  • 1
stkubr
  • 371
  • 1
  • 5
  • 15

0 Answers0