这个问题在这里已经有了答案:
How to specify "does not contain" in dplyr filter
(3 个回答)
4年前关闭。
我正在寻找一个 dplyr 等价物
SELECT user_id, item
FROM users
WHERE user_id NOT IN (1, 5, 6, 7, 11, 17, 18); -- admin accounts
我可以用
users %>% filter(user_id != 1)
但无法想象使用多个 &&
一路。有没有办法排除多行?
最佳答案
您可以使用 !
和 %in%
:
filtered_users <- filter(users, !user_id %in% c(1, 5, 6, 7, 11, 17, 18))
这是基于 https://stackoverflow.com/a/34444336/1152809 .我只是在谷歌上搜索“dplyr not in”,这是第一个结果。在学习新事物时,Google 是您的 friend 。另外,正如@thelatemail 所说,
%in%
是一个基 R 函数。
关于r - dplyr 排除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41234086/