I need to combine two xts objects of intraday OHLC data, a and b. One starts earlier, the other ends later and they overlap. What I need is a new xts object c that starts at the first period of a and ends with the last period of b. If for one period both a and b provide OHCLV a has priority, else take either of a and b.
For example:
> a
## a.Open a.High a.Low a.Close a.Volume
## 2014-02-18 09:55:00 184.14 184.46 184.07 184.11 5712100
## 2014-02-18 10:55:00 184.12 184.28 183.65 184.17 13912700
## 2014-02-18 11:55:00 184.17 184.49 184.12 184.38 7251000
## 2014-02-18 12:55:00 184.38 184.45 184.18 184.26 5521100
## 2014-02-18 13:55:00 184.26 184.40 184.11 184.15 4700300
## 2014-02-18 15:55:00 184.40 184.47 184.26 184.37 10324400
## 2014-02-18 16:05:00 184.38 184.38 184.20 184.24 20452900
## 2014-02-19 09:55:00 183.69 184.29 183.69 184.24 5445800
## 2014-02-19 10:55:00 184.25 184.95 184.16 184.74 18007800
> b
## b.Open b.High b.Low b.Close b.Volume
## 2014-02-14 15:55:00 183.96 184.06 183.15 183.99 18607278
## 2014-02-14 16:05:00 183.99 184.00 183.98 183.99 52504
## 2014-02-18 09:55:00 184.16 184.28 184.11 184.15 3932026
## 2014-02-18 10:55:00 184.14 184.49 184.12 184.40 7570591
## 2014-02-18 11:55:00 184.40 184.45 184.18 184.35 5201513
## 2014-02-18 12:55:00 184.35 184.40 184.11 184.16 4870456
## 2014-02-18 13:55:00 184.15 184.48 184.13 184.41 5824933
## 2014-02-18 14:55:00 184.41 184.47 184.26 184.42 7617463
## 2014-02-18 15:55:00 184.43 184.43 183.98 184.29 9575112
## 2014-02-18 16:00:00 184.27 184.27 184.26 184.27 1990
should result in:
> c
## c.Open c.High c.Low c.Close c.Volume
## 2014-02-14 15:55:00 183.96 184.06 183.15 183.99 18607278
## 2014-02-14 16:05:00 183.99 184.00 183.98 183.99 52504
## 2014-02-18 09:55:00 184.14 184.46 184.07 184.11 5712100
## 2014-02-18 10:55:00 184.12 184.28 183.65 184.17 13912700
## 2014-02-18 11:55:00 184.17 184.49 184.12 184.38 7251000
## 2014-02-18 12:55:00 184.38 184.45 184.18 184.26 5521100
## 2014-02-18 13:55:00 184.26 184.40 184.11 184.15 4700300
## 2014-02-18 14:55:00 184.41 184.47 184.26 184.42 7617463
## 2014-02-18 15:55:00 184.40 184.47 184.26 184.37 10324400
## 2014-02-18 16:05:00 184.38 184.38 184.20 184.24 20452900
## 2014-02-19 09:55:00 183.69 184.29 183.69 184.24 5445800
## 2014-02-19 10:55:00 184.25 184.95 184.16 184.74 18007800
Notice that the missing values for the 14:55:00 period in a are filled with the values from b.