Reputation: 39585
I am trying to compute distances in R, but in my data frame the first variable (column) is a ID, 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
Upvotes: 7
Views: 21737
Reputation: 61154
Maybe you're looking for this:
> DF <- DF[, -1]
> colnames(DF)[1] <- 'rownames'
> DF
rownames Amount1
1 15 15
2 9812 25
3 1672 89
Upvotes: 5
Reputation: 49033
Just use :
rownames(df) <- df$ID
Note that row names have to be unique if df is a data frame.
Upvotes: 13