I have a data frame that looks like:
ID CO1 CO2 ED1 ED2 max
1 1 2 1 3 3
2 1 3 3 2 3
3 4 2 2 1 3
4 3 3 4 4 4
...
10 1 1 1 1 1
How do I get R to give me the name(s) of the columns that contain a particular number contanined in the colum max and assign them to a new column, named “best”?
I want something like this:
ID CO1 CO2 ED1 ED2 max best
1 1 2 1 3 3 ED2
2 1 3 3 2 3 CO2
3 4 2 2 1 4 CO1
4 3 3 4 4 4 ED1
...
10 1 1 1 1 1 CO2
In case there are more values equal to the one contained in the max column (as for example in row 2 or row 10), one at random is fine.
I have seen several solution to problems similar to this one, but none that effectively works in my case.