1

I have a dataframe where the row names need to be the first column and assigned a header. I would prefer not to use any packages, just base functions in R. Hoping for a one liner.

Input:

             V1
Species1     31.76010
Species2     43.97335
Species3     40.29958

Desired output:

HeaderName   V1
Species1     31.76010
Species2     43.97335
Species3     40.29958
ecoevo
  • 11
  • 1
  • 1
  • 4

1 Answers1

2

You can use this df$HeaderName <- row.names(df) to assign your row indexes to a column HeaderName

Raymond W
  • 666
  • 5
  • 10
  • While this might answer the authors question, it lacks some explaining words and/or links to documentation. Raw code snippets are not very helpful without some phrases around them. You may also find [how to write a good answer](https://stackoverflow.com/help/how-to-answer) very helpful. Please [edit] your answer - [From Review](https://stackoverflow.com/review/low-quality-posts/22039826) – Nick Jan 27 '19 at 06:16