使用其他子集数据框删除行

时间:2018-05-20 10:17:05

标签: r

从完整的数据框:

df1 <- data.frame(pid = c(12,13,14,15,16,17,32,44,3,4,59,2,91), 
                 name = c("product1","product2","product3","product4",
                 "product5","product6","product7","product8","product9",
                 "product10","product11","product12","product43"))

使用像这样的索引/子集列表:

df2 <- data.frame(pid = c(12,13,14,4,2))

怎么可能删除pid值为df2的df1行?

1 个答案:

答案 0 :(得分:1)

使用%in%

> df1[!df1$pid %in% df2$pid, ]
   pid      name
4   15  product4
5   16  product5
6   17  product6
7   32  product7
8   44  product8
9    3  product9
11  59 product11
13  91 product43