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.
The example data
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)
I tried
library(dplyr)
df%>%
filter(!grepl("\\.",vals))
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
Maybe something like this:
df %>% group_by(gr) %>% filter(all(!grepl("\\.",vals)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With