Change row order in a matrix/dataframe

前端 未结 7 855
盖世英雄少女心
盖世英雄少女心 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 03:48

    Veeery late, but this seems to be working fast, does not need any extra packages and is simple:

    for(i in 1:ncol(matrix)) {matrix[,i] = rev(matrix[,i])}
    

    I guess that for frequent use, one would make a function out of it. Tested with R v=3.3.1.

提交回复
热议问题