Row wise Sorting in R

前端 未结 2 1916
小鲜肉
小鲜肉 2020-11-30 14:13

I would like to how to do a row wise sorting in csv using R. Here\'s the following data I have

Name  English Math  French
John    56    78    86
Sam     79           


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 14:43

    You can try:

    cbind(x[1],matrix(paste(colnames(x)[apply(x[,2:4],1,order,decreasing=TRUE)+1],
          apply(x[,2:4],1,sort,decreasing=TRUE)),ncol=3,byrow=TRUE))
    #  Name          1         2          3
    #1 John  French 86   Math 78 English 56
    #2  Sam    Math 97 French 86 English 79
    #3 Viru English 93   Math 44  French 34
    

提交回复
热议问题