Deleting text from row.names in a dataframe
1
0
Entering edit mode
3.1 years ago
salehm ▴ 10

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.1k views
ADD COMMENT
2
Entering edit mode
3.1 years ago
patelk26 ▴ 290

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))

ADD COMMENT
0
Entering edit mode

Thank you so much @patelk26

ADD REPLY

Login before adding your answer.

Traffic: 2564 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6