Skip to content

coalesce in its

2 messages · Omar Lakkis, Achim Zeileis

#
I have two data sets that I converted to its objects to get:
date  settle
1 2000-09-29 107.830
2 2000-10-02 108.210
3 2000-10-03 108.800
4 2000-10-04 108.800
5 2000-10-05 109.155
ts2>
        date  settle
1 2000-09-25 107.610
2 2000-09-26 107.585
3 2000-09-27 107.385
4 2000-09-28 107.595
5 2000-09-29 107.875
6 2000-10-02 108.805
7 2000-10-03 108.665
8 2000-10-04 109.280
9 2000-10-05 109.290

I want to get a list of the values of ts1 with the missing dates
substitute from ts2. When I do union(ts1,ts2) I get
1       1
2000-09-24      NA 107.610
2000-09-25      NA 107.585
2000-09-26      NA 107.385
2000-09-27      NA 107.595
2000-09-28 107.830 107.875
2000-10-01 108.210 108.805
2000-10-02 108.800 108.665
2000-10-03 108.800 109.280
2000-10-04 109.155 109.290

Other than looping, is there a way to get the first column with NA
values substituted from the second column?
#
On Mon, 4 Apr 2005 13:46:46 -0400 Omar Lakkis wrote:

            
If I understand you correctly, you want:

R> ts3 <- union(ts1, ts2)
R> repIndex <- is.na(ts3[,1])
R> ts3[repIndex, 1] <- ts3[repIndex, 2]
R> ts3[,1]
            settle
2000-09-25 107.610
2000-09-26 107.585
2000-09-27 107.385
2000-09-28 107.595
2000-09-29 107.830
2000-10-02 108.210
2000-10-03 108.800
2000-10-04 108.800
2000-10-05 109.155

hth,
Z