Order data frame by two columns in R

后端 未结 2 804
自闭症患者
自闭症患者 2020-12-05 05:36

I\'m trying to reorder the rows of a data frame by two factors. For the first factor i\'m happy with the default ordering. For the second factor i\'d like to impose my own c

2条回答
  •  渐次进展
    2020-12-05 06:30

    Try using a factor with the levels in the desired order and the arrange function from plyr:

    dat$apple <- factor(dat$apple,levels=appleOrdered)
    arrange(dat,orange,apple)
    

提交回复
热议问题