删除包含某些字符串的组 [英] Remove groups that contain certain strings

查看:65
本文介绍了删除包含某些字符串的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于删除行中包含某些字符串的组的问题,例如,如果包含。我想做到这一点而不中断管道。我的意思是不使用任何 join 函数。

I have an issue about removing the groups that contain certain strings in its rows for example if includes .. I would like to achive this without breaking the pipeline. I mean without using any join function.

示例数据

vals <- c("good","bad",'ugly',"good","bad.","ugly")

    gr <- gl(2,3)

vals gr
1 good  1
2  bad  1
3 ugly  1
4 good  2
5 bad.  2
6 ugly  2

df <- data.frame(vals,gr)

我尝试过

library(dplyr)
        df%>%
          filter(!grepl("\\.",vals))

仅删除该行符合条件的但我要删除整个 gr 2

which removes only the row that match the condition. But I want to remove entire gr 2.

 vals gr
1 good  1
2  bad  1
3 ugly  1
4 good  2
5 ugly  2


推荐答案

也许是这样的:

df %>% group_by(gr) %>% filter(all(!grepl("\\.",vals)))

这篇关于删除包含某些字符串的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆