Let us say we have the following data frame in R:
DF <- as.data.frame.matrix(matrix(sample(1:15,15),ncol=5,nrow=3))
V1 V2 V3 V4 V5
1 15 8 3 14 4
2 11 2 5 13 6
3 9 7 10 12 1
I'm trying to retrieve the column name of the top three values per row. I would like to get a new data frame with the following information:
1 V1 V4 V2
2 V4 V1 V5
3 V4 V3 V1
I tried by using apply and dapply but it is not working. I designed a function to use in apply but it is not working as expected. Could you give me any hint to tackle this. I think this should be of help.