-1

I have a dataframe with 4 columns. How do I give the first column a name?

enter image description here

I tried using dplyr but it doesn't work.

colnames(df)[0] <- "Test"
NelsonGon
  • 12,469
  • 5
  • 25
  • 52
Jane
  • 375
  • 3
  • 9

1 Answers1

3

That's not a column, those are the row names. Within the tidyverse there's a function to create a column out of them:

 df<-tibble::rownames_to_column(df, "test") 
iod
  • 7,094
  • 2
  • 15
  • 33