Hel lo I have a df such as
Groups COL1 COL2
G1 1 A
G1 1 C
G1 2 A
G1 2 B
G1 5 C
G1 6 C
G2 7 B
G2 7 B
G2 8 C
G3 10 C
G3 10 A
G3 11 B
G4 12 C
G4 12 C
and the idea is to add a new column COL3
and
group_by(Groups, COL1) %>%
mutate(COL3 = COL1(A>B>C))
the idea being that within groups and COL1, if two COL2 values are different, if A is present with A or C, all value become A, if A is not present but B is here, all value become B and if there is only C, all value become C (they already are).
so A > B and B > C here is the expected output :
Groups COL1 COL2 COL3
G1 1 A A
G1 1 C A
G1 2 A A
G1 2 B A
G1 5 C C
G1 6 C C
G2 7 B B
G2 7 B B
G2 8 C C
G3 10 C A
G3 10 A A
G3 11 B B
G4 12 C C
G4 12 C C
Does someone have an idea ?