Set simplify=FALSE
in your call 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"
Question
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 make a list of this xts
object with length 5.
but when I do this I lose the date and time... how can I create a list of replicate xts
objects without losing the xts
class?
> class(frame)
[1] "xts" "zoo"
> class( replicate(5, frame)[1])
[1] "character"
> replicate(5, frame)
, , 1
[,1]
[1,] "a"
[2,] "a"
[3,] "a" # seriously... :(
.........
Solution
Set simplify=FALSE
in your call 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"