R move index column to first column [duplicate]

六眼飞鱼酱① 提交于 2021-02-08 05:16:45

问题


I have following data frame:

              RMSE
A         0.03655830
B         0.24513014
C         0.02009853
D         0.02223135

I want to move column that has A,B,C,D to be the first column and add an index to the data.frame.


回答1:


try this:

df <- cbind(newColName = rownames(df), df)
rownames(df) <- 1:nrow(df)

hope this is what you meant, the result will be:

  newColName       RMSE
1          A 0.03655830
2          B 0.24513014
3          C 0.02009853
4          D 0.02223135


来源:https://stackoverflow.com/questions/36396911/r-move-index-column-to-first-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!