How to put a column as row names in a Dataframe

I am trying to calculate the distances in R, but in my data frame the first variable (column) is an identifier, for example, I have this:

  rownames ID Amount1
 1 0015 15
 2 9812 25
 3 1672 89

I would like to have something like this:

  rownames amount1
    0015 15
    9812 25
    1672 89
+6
source share
2 answers

Perhaps you are looking for this:

> DF <- DF[, -1] > colnames(DF)[1] <- 'rownames' > DF rownames Amount1 1 15 15 2 9812 25 3 1672 89 
+2
source

Just use:

 rownames(df) <- df$ID 

Note that line names must be unique if df is a data frame.

+5
source

All Articles