How to reverse the order of a dataframe in R

前端 未结 7 873
终归单人心
终归单人心 2021-01-03 18:37

I\'ve endlessly looked for this and somehow nothing has solved this simple problem.

I have a dataframe called Prices in which there are 4 columns, one of wh

7条回答
  •  臣服心动
    2021-01-03 18:54

    If you wanted to do this in base R use:

    df <- df[rev(seq_len(nrow(df))), , drop = FALSE]
    

    All other base R solutions posted here will have problems in the edge cases of zero row data frames (seq(0,1) == c(0, 1), that's why we use seq_len) or single column data frames (data.frame(a=7:9)[3:1,] == 9:7, that's why we use , drop = FALSE).

提交回复
热议问题