Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replicate() class xts into a 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 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... :(

.........
like image 692
user1320502 Avatar asked Jun 17 '26 21:06

user1320502


1 Answers

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" 
like image 165
Joshua Ulrich Avatar answered Jun 20 '26 09:06

Joshua Ulrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!