This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Deleting text from row.names in a dataframe

Hi,

I have dataframe with 1st column is Sample_ID, samples are listed like this:

sample1_s2 sample2_s5 sample3_s23

I want to remove "_s2", "_s5", "_s23" from sample names.

Is there away to remove whatever after "_"?

Thanks.

rna-seq

1 answer

You could try using gsub in R:

To remove everything after_ including _ : gsub('_s.*','',rownames(df))

To retain _ in row names you could try: gsub('(.*_)s.*','\\1',rownames(df))

Thank you so much @patelk26

Log in to answer this question.