1

I would like to keep only the sample that do not have "Chemo" in the Treatment column.

I tried with filter, but this don't work as it don't remove the whole group and keep group B.

df %>%
  group_by(sample) %>%
  filter(Treatment!="Chemo")

In:

> data.frame(sample=c("A","A","A","A","B","B","C","C"), Treatment=c("Chemo","Chemo", "Chemo","Chemo","Hormon","Chemo","Hormon","Hormon"))
  sample Treatment
1      A     Chemo
2      A     Chemo
3      A     Chemo
4      A     Chemo
5      B    Hormon
6      B     Chemo
7      C    Hormon
8      C    Hormon

Out:

7      C    Hormon
8      C    Hormon

Maybe this?

df %>%
  group_by(sample) %>%
  filter(!any(Treatment=="Chemo"))
user2300940
  • 2,355
  • 1
  • 22
  • 35

0 Answers0