Here is an example of data:
df <- data.frame("ID1" = c("A","A","B","C"),
"Wt1" = c(0.8,0.6,0.4,0.5),
"ID2" = c("B","A","C","B"),
"Wt2" = c(0.1,0.4,0.5,0.5),
"ID3" = c("C",NA,"C",NA),
"Wt3" = c(0.1,NA,0.1,NA))
And I would like to create columns (vote) in a dataframe, which is based on argmax wt from groups ID1, ID2, ID3. For example, in row 3 of the example data, the sum wt for "B" is 0.4 and the sum wt for "C" is 0.6, so vote = "C".
So, the result will be similar to
ID1 Wt1 ID2 Wt2 ID3 Wt3 vote
1 A 0.8 B 0.1 C 0.1 A
2 A 0.6 A 0.4 <NA> NA A
3 B 0.4 C 0.5 C 0.1 C
4 C 0.5 B 0.5 <NA> NA C
In the case of binding (line 4 in the example), simply select any of the identifier values. Can anyone suggest a solution?