Reputation:
How to change Row name of a particular column in R dataframe:
<df
Name Value
A 10
B 20
C 30
I want output to be:
Name Value
AAA 10
BBB 20
CCC 30
I have tried data.table library but it couldn't work.
library(data.table)
my_df <- setattr(df$Name, "row.names", c("AAA", "BBB", "CCC"))
Upvotes: 0
Views: 153
Reputation: 116
Looks like the name column is it's own column. See the code below
sample <- data.frame(Name = c("A", "B", "C"), Value = c(10,20,30))
Looks like this:
> sample
Name Value
1 A 10
2 B 20
3 C 30
Now Try:
sample$Name <- c("AAA", "BBB", "CCC")
Yields:
> sample
Name Value
1 AAA 10
2 BBB 20
3 CCC 30
Upvotes: 3