我刚刚对两个数据集执行了概率链接。称为“数据”的输出数据集包含两个原始数据集 ID_A 和另一个 ID_B 的标识号,以及关联分数“match_score”。
ID_A<-c('123','124','125','125','126','127','127','128','129')
ID_B<-c('777','778','787','799','762','762','777','999','781')
Match_score<-c(28.1,15.6,19.7,18.9,36.1,55.1,28.7,19.5,18.2)
data<-data.frame(ID_A,ID_B,Match_score)
ID_A 和 ID_B 有多种组合。我只想选择要配对的顶部链接,然后将它们从选择过程中删除以进行进一步的链接。理想的输出是...
ID_A ID_B Match_score
127 762 55.1
123 777 28.1
125 787 19.7
128 999 19.5
129 781 18.2
124 778 15.6
ID_A:由于 ID_B (762),126 不匹配,另一个 ID_A (127) 的 match_score 更高。
ID_B:799 不匹配,因为 ID_A(125) 与 (787) 的 match_score 更大
任何帮助将不胜感激!
我有解决 SAS 问题的方法,但是我很难转换为 R。
proc sort data=one;
by descending match_score ID_A ID_B;
run;
data want;
if _n_=1 then do;
dcl hash ha();
ha.definekey('ID_A');
ha.definedone();
dcl hash hb();
hb.definekey('ID_B');
hb.definedone();
end;
set one;
if ha.check()*hb.check() then do;
output;
ha.add();
hb.add();
end;
run;