How do I order by row.names in dataframe

后端 未结 2 2104
傲寒
傲寒 2021-01-16 17:31

This is rather tricky, and it doesn\'t seem to require the same approach for ordering by a typical column in a data frame. I have something that looks like this:

2条回答
  •  猫巷女王i
    2021-01-16 18:11

    I've had this problem before. Here's how I solved it. Using some iris sample data from base R,

    > dat <- iris[sample(nrow(iris), 10), ]
    > rn <- rownames(dat)
    > dat[order(as.numeric(rn)), ]
    

提交回复
热议问题