Replace column name in dataframe

Dear R community,
Does anyone know how we remove default column names (integer value) in data frame to the first row in R studio. I attached a picture to be more precise.
Thank you very much!

I have to admit I have never seen a display like that. Can you explain how this data frame was made? Also, I notice that some of the values in the first row are not valid column names, so you probably need to change them before using them.

The data frame was made from an excel sheet and later column names were transposed to row names using t() function. I created a new data frame from this sheet and view looks like this (see attachment). Unfortunately, I still see this wrong column name by default (X1, X2, X3 and .....). Thanks for your comment on the first raw as not valid column name I will be fixing that soon.

The version of the data frame in your most recent post looks closer to a usable form. Please fix the text in the first row if you can and then post the output of the command like


In that command, you have to use the actual name of your data frame where I have used DF. The output of the dput function will provide a command to reproduce the first six rows and eight columns of your data frame. We can then use that to build an example of how to fix the column names.

Thanks, I fixed the first raw into valid identifiers using gsub(). Later I used the dput() (see script below).

dput (head(THCA_RNA_seq_RSEM_normalize_valid_name_trans2[1:8]))
c("Condition", "Primary solid Tumor", "Primary solid Tumor",
"Primary solid Tumor", "Primary solid Tumor", "Primary solid Tumor"
Any other idea what else I am missing to make first row as data frame column variables.

you havent understood the purpose of dput.
dput is not there for you to tell us what parameters to pass to it.
Its for you to run, and share with us, the result printed to your console, of your having run it.
this allows us to have your data.


df <- tribble( ~`1`,~`2`,~`3`,

names(df) <- slice(df,1) %>% paste0

df <- slice(df,-1)

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