r - dplyr 排除行

标签 r dplyr

这个问题在这里已经有了答案:





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/

相关文章:

r - Plotly 图表在 Shiny Dashboard 中无法正确呈现

r - 为什么 ggplot 中的此命令返回错误?

r - 线性插值时间序列中的缺失值

r - 管道到 R 函数中的 return() 时的奇怪行为?

r - 制作 dplyr 过程的自定义函数

r - 使用 tidyverse 和 broom : Same dependent variable, 不同自变量的许多回归

sql - 使用 RODBC 的参数化查询

html - 如何调整包含plotly的div以绘制尺寸,使其不与文档重叠

r - 在 R 的行中交换值

r - ggplot 使用分组日期变量(例如 year_month)