我有一个具有以下形状的数据框“A”
log P1 P2 P3 P4 P5 Method Round #TSamples #Samples0 #Samples1 FP TN TP FN Time Det_Time
data1 2 0 0 0 LOF 1 3 3 0 0 3 0 0 0.00800108909606934 1
data1 2 0 0 0 Mahalanobis 1 3 3 0 0 3 0 0 0.00100016593933105 1
data1 2 0 0 0 Cook 1 3 3 0 0 3 0 0 0.00900101661682129 1
...........
另一个带有
的数据框“B”log P1 P2 P3 P4 P5 Method Round #TSamples #Samples0 #Samples1 FP TN TP FN Time Det_Time
data1 2 0 0 0 Mahalanobis 1 3 3 0 0 3 0 0 0.00200080871582031 1
data1 3 0 0 0 Mahalanobis 1 3 3 0 0 3 0 0 0.000999927520751953 1
基本上,当列“P1”,“P2”,“P3”时,我想从数据帧A中替换数据帧A中的行“FP”,“TN”,“TP”和“FN” ,“P4”,“P5”,“方法”和“回合”匹配A和B数据帧。
劳尔
答案 0 :(得分:0)
这样的事情:
require(sqldf)
C <- sqldf('select A.log, A.P1, A.P2, A.P3, A.P4, A.P5, A.Method, A.Round, "A.#TSamples", "A.#Samples0", "A.#Samples1", B.FP, B.TN, B.TP, B.FN, A.Time, A.Det_Time
from A
inner join B on (A.log = B.log and
A.P1 = B.P1 and
A.P2 = B.P2 and
A.P3 = B.P3 and
A.P4 = B.P4 and
A.P5 = B.P5 and and
A.Method = B.Method and
A.Round = B.Round)
')
C <- rbind(A,C)
C <- C[!duplicated(C[c("log", "P1", "P2", "P3", "P4", "P5", "Method", "Round", "#TSamples", "#Samples0", "#Samples1", "Time", "Det_Time")]),]