Search code examples
rxts

rbind time series and drop identical dates


Both x and y overlap on 2018-08-08. How can I combine the rows where I keep all values of x, then only retain values of y that do not overlap the same index/date value of x?

x <- as.xts(1:10, Sys.Date()+1:10). 
y <- as.xts(11:20, Sys.Date()+10:19). 
z <- rbind(x,y)

2018-07-30    1
2018-07-31    2
2018-08-01    3
2018-08-02    4
2018-08-03    5
2018-08-04    6
2018-08-05    7
2018-08-06    8
2018-08-07    9
2018-08-08   10
2018-08-08   11
2018-08-09   12
2018-08-10   13
2018-08-11   14
2018-08-12   15
2018-08-13   16
2018-08-14   17
2018-08-15   18
2018-08-16   19
2018-08-17   20

Should be missing the 2018-8-8 11 value for y

2018-07-30    1
2018-07-31    2
2018-08-01    3
2018-08-02    4
2018-08-03    5
2018-08-04    6
2018-08-05    7
2018-08-06    8
2018-08-07    9
2018-08-08   10
2018-08-09   12
2018-08-10   13
2018-08-11   14
2018-08-12   15
2018-08-13   16
2018-08-14   17
2018-08-15   18
2018-08-16   19
2018-08-17   20

Solution

  • Subset the y's to omit those containing an index in x

    z <- rbind(x,y[!(index(y) %in% index(x))])