2つの目的のために、複数のフレームがあります。各フレームは、インデックス列と値列の2つの列で構成されています。
sz<-5;
frame_1<-data.frame(index=sort(sample(1:10,sz,replace=F)),value=rpois(sz,50));
frame_2<-data.frame(index=sort(sample(1:10,sz,replace=F)),value=rpois(sz,50));
frame_1:
index value
1 49
6 62
7 58
8 30
10 50
frame_2:
index value
4 60
5 64
6 48
7 46
9 57
目標は、3番目のフレームframe_3を作成することです。このフレームのインデックスは、frame_1とframe_2のインデックスの和集合になります。
frame_3<-data.frame(index = sort(union(frame_1$index,frame_2$index)));
これは、value_1とvalue_2の2つの追加の列で構成されます。
frame_3$value_1はframe_1$valueから入力され、frame_3$value_2はframe_2$valueから入力されます。
これらは次のように入力する必要があります:frame_3:
index value_1 value_2
1 49 NA
4 49 60 # value_1 is filled through with previous value
5 49 64 # value_1 is filled through with previous value
6 62 48
7 58 46
8 30 46 # value_2 is filled through with previous value
9 30 57 # value_1 is filled through with previous value
10 50 57 # value_1 is filled through with previous value
数十万のレコードを処理しているので、効率的なソリューションを探しています