0

So i currently have a dataframe in R where:

      degree

54     0.65
43     0.76
31     0.67

and by executing:

df[1]

it prints out the first row:

54       0.65

I'm trying to assign a column name to the first column, where i get:

vertex     degree

  54        0.65
  43        0.76
  31        0.67

So i can query the dataframe column separately:

df$vertex
df$degree

Is there any possible ways i could do this?

Maxxx
  • 3,688
  • 6
  • 28
  • 55

1 Answers1

0

We can use rownames_to_column

library(tidyverse)
rownames_to_column(df1, 'vertex')

Or with base R

data.frame(df1, vertex = row.names(df1))
akrun
  • 874,273
  • 37
  • 540
  • 662