I have a table like below, would like to crate suggestions based on row value in R.
This is what I have -
id class1 class2 class3 class4
A 0.98 0.48 0.21 0.99
B 0.22 0.31 0.41 0.11
C 0.70 0.81 0.61 0.21
I would like to have two new columns ('sugg1', 'sugg2') that will give the column names of the two top maximum values for each row i.e. for the first row, 0.99 is the maximum value, so its corresponding column name is class4
, and the next max value is 0.98 for which the column name is class1
.
id class1 class2 class3 class4 sugg1 sugg2
A 0.98 0.48 0.21 0.99 class4 class1
B 0.22 0.31 0.41 0.11 class3 class2
C 0.70 0.81 0.61 0.21 class2 class1