Problema
Queremos seleccionar las filas de A que no están presentes en in B. El resultado esperado es el data frame C.
A <- structure(list(Var1 = c(1L, 2L, 4L, 4L, 6L), Var2 = c(3L, 5L,
5L, 5L, 7L), Var3 = c(4L, 6L, 7L, 8L, 9L)), .Names = c("Var1",
"Var2", "Var3"), class = "data.frame", row.names = c(NA, -5L))
B <- structure(list(Var1 = 1:2, Var2 = c(3L, 5L), Var3 = c(4L, 6L)), .Names = c("Var1", "Var2", "Var3"), class = "data.frame", row.names = c(NA, -2L))
# A
Var1 Var2 Var3
1 1 3 4
2 2 5 6
3 4 5 7
4 4 5 8
5 6 7 9
# B
Var1 Var2 Var3
1 1 3 4
2 2 5 6
# C
Var1 Var2 Var3
3 4 5 7
4 4 5 8
5 6 7 9
Solución
C <- rbind(A, B)
C[!(duplicated(C) | duplicated(C, fromLast = TRUE)), ]
library(dplyr)
anti_join(A, B)
library(sqldf)
C <- sqldf('SELECT * FROM A EXCEPT SELECT * FROM B')
library(data.table)
setDT(df1)[!df2, on = names(df1)]
Entradas relacionadas
Referencias
No hay comentarios:
Publicar un comentario