Robert Kubrick
Robert Kubrick

Reputation: 8713

Merge two xts time-series in a single stream

Given these 2 xts objects:

> X
2012-02-01 09:31:40 2012-02-01 09:31:50 2012-02-01 09:33:30 
         -3.8993007          -2.0860621          -0.6308867
> Y
2012-02-01 09:32:00 2012-02-01 09:32:10 2012-02-01 09:32:20
          1.1983066          -0.2071149           0.3887806

How can I join them by time and have a single column object with indexes 9:31:40, 9:31:50, 9:32:00, 9:32:10, 9:32:20, 9:33:30? That is, I need to stream the two object in a single sequence (not merge the two columns X/Y in a combined matrix).

Upvotes: 2

Views: 6009

Answers (1)

GSee
GSee

Reputation: 49810

> X <- xts(rnorm(1:10), Sys.time() + 1:10)
> Y <- xts(rnorm(1:10), Sys.time() - 10:1)
> rbind(X, Y)
                          [,1]
2012-05-15 13:07:25  1.1022975
2012-05-15 13:07:26 -0.4755931
2012-05-15 13:07:27 -0.7094400
2012-05-15 13:07:28 -0.5012581
2012-05-15 13:07:29 -1.6290935
2012-05-15 13:07:30 -1.1676193
2012-05-15 13:07:31 -2.1800396
2012-05-15 13:07:32 -1.3409932
2012-05-15 13:07:33 -0.2942939
2012-05-15 13:07:34 -0.4658975
2012-05-15 13:07:36  0.1340882
2012-05-15 13:07:37 -0.4906859
2012-05-15 13:07:38 -0.4405479
2012-05-15 13:07:39  0.4595894
2012-05-15 13:07:40 -0.6937202
2012-05-15 13:07:41 -1.4482049
2012-05-15 13:07:42  0.5747557
2012-05-15 13:07:43 -1.0236557
2012-05-15 13:07:44 -0.0151383
2012-05-15 13:07:45 -0.9359486

Upvotes: 5

Related Questions