Here's the sample dataset:
sample <- data.frame(ID = c(100,100,101,101,102,102,103,103), flag = c(0,0,1,1,0,1,0,0))
ID flag
1 100 0
2 100 0
3 101 1
4 101 1
5 102 0
6 102 1
7 103 0
8 103 0
I would like to filter the rows, based on the value in flag column, and keep only the IDs for which "all" the corresponding flag values are 0. In this case, the remaining rows are 1, 2, 7, and 8.