Delete rows that exist in another data frame?

早过忘川 提交于 2019-11-26 18:52:00

You need the %in% operator. So,

df1[!(df1$name %in% df2$name),]

should give you what you want.

  • df1$name %in% df2$name tests whether the values in df1$name are in df2$name
  • The ! operator reverses the result.

This is sometimes called an anti-join:

library(dplyr)
anti_join(df1, df2, by = "name")
user2635283
df1[!(as.character(df1$jobId) %in% as.character(df2$name)), ]

I had to add as.character to my execution because name is not a character but a factor instead. Isn't %in% supposed to convert this directly?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!