假设我有两个 Dataframe ,如下所示
df1 <- data.frame(ID = c("A","B","F","G","B","B","A","G","G","F","A","A","A","B","F"),
code = c(1,2,2,3,3,1,2,2,1,1,3,2,2,1,1),
class = c(2,4,5,5,2,3,2,5,1,2,4,5,3,2,1))
df2 <- data.frame(ID = c("G","F","C","F","B","A","F","C","A","B","A","B","C","A","G"),
code = c(1,2,2,3,3,1,2,2,1,1,3,2,2,1,1),
class = c(2,4,5,5,2,3,2,5,1,2,4,5,3,2,1))
我想检查df1$ID
和df2$ID
中的重复项,如果df1
中不存在ID,则删除df2
中的所有行,这样新的 Dataframe 将如下所示:
df3 <- data.frame(ID = c("G","F","F","B","A","F","A","B","A","B","A","G"),
code = c(1,2,3,3,1,2,1,1,3,2,1,1),
class = c(2,4,5,2,3,2,1,2,4,5,2,1))
3条答案
按热度按时间von4xj4u1#
使用
%in%
:vwhgwdsa2#
您可以使用'intersect'函数来解决这个问题。
ldxq2e6h3#
我想把
semi_join
加进去。