I have a dataframe such as
Groups subgroups Species Value
G1 subg1 Sp1 NO
G1 subg1 Sp1 YES
G1 subg1 Sp2 NO
G2 subg5 Sp7 YES
G2 subg6 Sp7 NO
G2 subg7 Sp7 NO
G2 subg7 Sp7 YES
G3 subg1 Sp1 NO
G3 subg1 Sp1 NO
and I would like to fill a new Value2
column where within each Groups
, subgroups
and Species
with "YES" if there is at least one YES within this group, and NO is there is none.
I should then get :
Groups subgroups Species Value Value2
G1 subg1 Sp1 NO YES
G1 subg1 Sp1 YES YES
G1 subg1 Sp2 NO NO
G2 subg5 Sp7 YES YES
G2 subg6 Sp7 NO NO
G2 subg7 Sp7 NO YES
G2 subg7 Sp7 YES YES
G3 subg1 Sp1 NO NO
G3 subg1 Sp1 NO NO