How to select rows according to column value conditions

Viewed 2194

I have a data set which looks like the following (partially):

id  name    dummy
1   Jane    1
1   Jane    0
1   Jane    1
2   Mike    0
2   Mike    0
2   Mike    0
2   Mike    0
2   Mike    0
3   Tom     1
3   Tom     1
3   Tom     0
3   Tom     0

I'm trying to eliminate the people where ALL of the variable dummy is 0. So for instance, Tom and Jane would not be eliminated because they have dummy variable 0 or 1, but Mike will be eliminated because he has all 0s. So I would want in the end

   id   name    dummy
    1   Jane    1
    1   Jane    0
    1   Jane    1
    3   Tom     1
    3   Tom     1
    3   Tom     0
    3   Tom     0

I thought about sorting the data frame according to dummy but I can't seem to figure out how to deal with the fact that I'm only trying to eliminate the people who only has 0 values for the variable dummy. Any suggestions would be really helpful!

4 Answers
Related