在data.frame 2中查找data.frame 1但没有的行

Roc*_*cer 1 diff r dataframe

我有一个data.frame(Data)和这个data.frame(Data2)的子集

set.seed(1)
Data <- data.frame(id = seq(1, 10), 
  Diag1 = sample(c("A123", "B123", "C123"), 10, replace = TRUE), 
  Diag2 = sample(c("D123", "E123", "F123"), 10, replace = TRUE), 
  Diag3 = sample(c("G123", "H123", "I123"), 10, replace = TRUE), 
  Diag4 = sample(c("A123", "B123", "C123"), 10, replace = TRUE), 
  Diag5 = sample(c("J123", "K123", "L123"), 10, replace = TRUE), 
  Diag6 = sample(c("M123", "N123", "O123"), 10, replace = TRUE), 
  Diag7 = sample(c("P123", "Q123", "R123"), 10, replace = TRUE))

Data2 <- Data[1:4,]
Run Code Online (Sandbox Code Playgroud)

如何获得两个data.frames的"差异"?我正在寻找Data中但不在Data2中的行.

我认为这样的数据[!Data2]应该有效,但事实并非如此.

谢谢!

The*_*Man 5

我认为你正在使用data.table构造data.frame.这应该工作 -

library(data.table)
Data <- data.table(Data)
Data2 <- data.table(Data2)

setkeyv(Data,colnames(Data))
setkeyv(Data2,colnames(Data2))

Data[!Data2]
Run Code Online (Sandbox Code Playgroud)