Set row.names for dataframe

I have a basic question regarding dataframe that i am unable to resolve.
I have a data frame as follows:

my_df <- structure(list(sum = c(22761, 18938, 18383, 30258, 52773, 36072, 
 35766, 22068, 23100, 49819, 16691)), 
class = "data.frame", row.names = c("group0", 
"group1", "group2", "group3", "group4", 
"group5", "group6", "group7", "group8", 
  "group9", "group10"))

I want to set row.names as " groups" and need out as follows:

Screenshot 2023-02-01 at 4.34.39 PM

How can I do that?

Regards
Hira

Try

my_df$groups <- row.names(my_df)

To rearrange into the order you want

my_df <- my_df[, c(2,1)]
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.