Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R move index column to first column [duplicate]

Tags:

dataframe

r

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.

like image 380
add-semi-colons Avatar asked Apr 04 '16 07:04

add-semi-colons


1 Answers

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
like image 148
cccmir Avatar answered Oct 15 '22 15:10

cccmir