Supopose I have a dataframe df
> df
ID Year Weight
1 Brown 1960 5.0
2 Green 1990 3.0
3 Yellow 1961 4.8
4 Green 1994 7.0
5 Green 1993 6.0
6 Brown 1964 8.0
7 Yellow 1960 4.6
If I want to subset all IDs with a weight greater than or equal to 5, I will simply say:
> df[df$Weight >= 5, ]
ID Year Weight
1 Brown 1960 5
4 Green 1994 7
5 Green 1993 6
6 Brown 1964 8
Unfortunately, the Green under year 1990 has been left out because the weight is less than 5. Is there a way that can retain all IDs as long as one of their weights is greater than or equal to 5?
Desired output
> output
ID Year Weight
1 Green 1990 3
2 Green 1993 6
3 Green 1994 7
4 Brown 1960 5
5 Brown 1964 8
Many thanks!