How to order a data frame by one descending and one ascending column?

前端 未结 10 1704
庸人自扰
庸人自扰 2020-12-02 13:02

I have a data frame, which looks like that:

    P1  P2  P3  T1  T2  T3  I1  I2
1   2   3   5   52  43  61  6   \"b\"
2   6   4   3   72  NA  59  1   \"a\"
3         


        
10条回答
  •  余生分开走
    2020-12-02 13:30

    The default sort is stable, so we sort twice: First by the minor key, then by the major key

    rum1 <- rum[order(rum$I2, decreasing = FALSE),]
    rum2 <- rum1[order(rum1$I1, decreasing = TRUE),]
    

提交回复
热议问题