I have multiple datasets with the following format
head(averagetable)
Group.1 Moving Feeding Standing
1 cluster1 0.05632530 0.1722892 0.7503012
2 cluster2 0.09220779 0.2644481 0.6118506
3 cluster3 0.04863636 0.1268182 0.7993182
I'm quite new to R and but my assignment is simple:
1) I would like to replace the name cluster# in Group.1 by Standing in the row with the highest value in column Standing.
2) The name Moving/Feeding to the second highest value of column Standing
3) The name Feeding/Moving to the thirsd highest value of column Standing.
Hence the output:
print(averagetable)
Group.1 Moving Feeding Standing
1 Moving/Feeding 0.05632530 0.1722892 0.7503012
2 Feeding/Moving 0.09220779 0.2644481 0.6118506
3 Standing 0.04863636 0.1268182 0.7993182
Hope this was clear enough. Note that replacing the strings using order() doesn't suit my needs as I have multiple dataframes and values might be different. I'm guessing ifelse() is the function to use but I'm guessing a for-loop needs to be implemented an I'm unsure on how to do that.