Replicate () class xts to list

I have an xts object frame

frame <- structure(c("a", "a", "a"), .Dim = c(3L, 1L), index = structure(c(946702800, 
946749600, 946796400), tzone = "", tclass = c("POSIXct", "POSIXt"
)), class = c("xts", "zoo"), .indexCLASS = c("POSIXct", "POSIXt"
), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "")


> frame
                    [,1]
2000-01-01 05:00:00 "a" 
2000-01-01 18:00:00 "a" 
2000-01-02 07:00:00 "a" 

I want to create a list of this object xtswith a length of 5.

but when I do this, I lose the date and time ... how can I create a list of replicated objects xtswithout losing the class xts?

> class(frame)
[1] "xts" "zoo"
> class( replicate(5, frame)[1])
[1] "character"

> replicate(5, frame)
, , 1

     [,1]
[1,] "a" 
[2,] "a" 
[3,] "a"    # seriously... :(

.........
+3
source share
1 answer

Set simplify=FALSEin your appeal to replicate:

> replicate(5, frame, simplify=FALSE)
[[1]]
                    [,1]
2000-01-01 05:00:00 "a" 
2000-01-01 18:00:00 "a" 
2000-01-02 07:00:00 "a" 
+2
source

All Articles