Reputation:
I want to convert rownames in my dataframe into first column
Example intput:
y
species1 3.783584
species2 3.696341
species3 3.968285
Desired output:
x y
species1 3.783584
species2 3.696341
species3 3.968285
Upvotes: 1
Views: 40
Reputation: 521249
Just assign the row names to a new column:
df$x <- rownames(df)
df <- df[,c("x", "y")]
The second step is only necessary if, for some reason, you care about column order.
If you also want to revert the row names to the numerical sequence they would have by default, you may do so via:
rownames(df) <- seq(nrow(df))
Upvotes: 1