0

I have a dataframe with column 0 having the variables:

my dataframe

How do I get this dataframe to have column 0 as the numbered column and the current column 0 to be a "variable" column (which would be column 1)? I have shown an example below:

my outcome

Nick
  • 207
  • 1
  • 2
  • 11

1 Answers1

4

We can use rownames_to_column from tibble

library(tibble)
df1 <- rownames_to_column(df1, "Variable")

Or using base R

df1$Variable <- row.names(df1)
row.names(df1) <- NULL
akrun
  • 874,273
  • 37
  • 540
  • 662