R - 替换选择性行数据框
R - Replace selective rows data frame
我有一个具有以下形状的数据框 "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
基本上,当列 [ =26=、"P2"、"P3"、"P4"、"P5"、"Method" 和 "Round" 在 A 和 B 数据帧中匹配。
劳尔
像这样:
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")]),]
我有一个具有以下形状的数据框 "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
基本上,当列 [ =26=、"P2"、"P3"、"P4"、"P5"、"Method" 和 "Round" 在 A 和 B 数据帧中匹配。
劳尔
像这样:
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")]),]