I have the following dataframe (df) - there are more columns, but these are the relevant columns:
ID Cost
1 $100
1 $200
2 $50
2 $0
2 $40
3 $10
4 $100
5 $0
5 $50
I would like to subset this dataframe such that if any of the costs for a particular ID = $0, then it should remove all those rows (i.e. all the rows for that particular ID.)
Therefore, in this example, ID 2 and 5 contain a $0, so all of ID 2 and ID 5 rows should be deleted.
Here is the resulting df I would like:
ID Cost
1 $100
1 $200
3 $10
4 $100
Could someone help with this? I tried some combinations of the subset
function, but it didn't work.
** On a similar note: I have another dataframe with "NA"s - could you help me figure out the same problem, in case it were NAs, instead of 0's.
Thanks in advance!!