I have 2 data frames df1 and df2.
df1 <- data.frame(c1=c(\"a\",\"b\",\"c\",\"d\"),c2=c(1,2,3,4) )
df2 <- data.frame(c1=c(\"
I remember coming across this exact issue quite a few months back. Managed to sift through my Evernote one-liners.
Note: This is not my solution. Credit goes to whoever wrote it (whom I can't seem to find at the moment).
If you don't worry about rownames then you can do:
df1[!duplicated(rbind(df2, df1))[-seq_len(nrow(df2))], ]
# c1 c2
# 1 a 1
# 2 b 2
Edit: A data.table solution:
dt1 <- data.table(df1, key="c1")
dt2 <- data.table(df2)
dt1[!dt2]
or better one-liner (from v1.9.6+):
setDT(df1)[!df2, on="c1"]
This returns all rows in df1 where df2$c1 doesn't have a match with df1$c1.