Rename rows in a dataframe

Hi there,

I have a data frame called Data that I want to analyse with some basic statistics such as ACP.
The first column of my object regroups the names of the products Data$Food product that are then analysed in the next columns.
In order to make plots clearer I would like to rename the rows of my dataframe with the first column.
I make some researches, I tried with this function :

(setattr(Data, "row.names", Data$`Food product`))

Unfortunately, the rows names have not changed.

Do you have any idea how could I resolve this ?

The tibble package has a function for this. The column_to_rownames function does require that the column does not have duplicate values, so I am not sure this will work without using the actual data set. However, you might be able to use this:

tibble::column_to_rownames(Data, var = 'Food Product')
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.