Change row order in a matrix/dataframe

前端 未结 7 860
盖世英雄少女心
盖世英雄少女心 2020-11-30 03:15

I need to change/invert rows in my data frame, not transposing the data but moving the bottom row to the top and so on. If the data frame was:

1 2 3 
4 5 6
7         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 04:03

    You can reverse the order of a data.frame using the dplyr package:

    iris %>% arrange(-row_number())
    

    Or without using the pipe-operator by doing

    arrange(iris, -row_number())
    

提交回复
热议问题