dplyr过滤器语句不在data.frame的表达式中 [英] dplyr filter statement not in expression from a data.frame
本文介绍了dplyr过滤器语句不在data.frame的表达式中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在dplyr中的data.frame中使用not in语句,但是它不起作用.我想从data.frame中排除值,因为我确实有很多星期数.下面是一个示例
I would like to use not in statement with a data.frame in dplyr but it is not working. I would like to exclude values from a data.frame since I do have huge week numbers. Below is an example
df1 = data.frame(week=c(1,2,3,4,5,6),sales=c(10,24,23,54,65,45))
week_e=data.frame(week=c(2,5))
所以我想从df1中排除week_e数据框中的几周,以下是代码 而且它不起作用.请帮忙!谢谢.
so I would like to exclude weeks in week_e data frame from df1 and below is code and it is not working. Please help! Thank you.
df1 %>%
filter(!week %in% week_e)
week sales
1 1 10
2 2 24
3 3 23
4 4 54
5 5 65
6 6 45
推荐答案
实际上我得到了答案.在week_e data.frame中添加一个取消列表,即可解决
Actually I got the answer. Add an unlist to the week_e data.frame then it is solved
df1 = data.frame(week=c(1,2,3,4,5,6),sales=c(10,24,23,54,65,45))
week_e=unlist(data.frame(week=c(2,5)))
df1 %>%
filter(!week %in% week_e)
week sales
1 10
3 23
4 54
6 45
这篇关于dplyr过滤器语句不在data.frame的表达式中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文