0

I have dataframe containing following two columns

Tumor_Barcode    SEX
     MEL-1   Male
     MEL-11   Male
     MEL-12 Female
     MEL-13   Male

I want to recode column Tumor_Barcode and output should be as following.

Tumor_Barcode   SEX
     sample-1   Male  
     sample-11   Male 
     sample-12 Female 
     sample-13   Male 

Is there anyway i can do it in R? may be something with mutate function from dplyr or anything better?

Data:

Tumor_Barcode<-c(" MEL-1","MEL-11","MEL-12","MEL-13")
Sex<-c("Male", "Male", "Female", "Male")
DF1<-data.frame(Tumor_Barcode,Sex)
Aryh
  • 479
  • 1
  • 4
  • 16

1 Answers1

1

Using stringr

library(stringr)
DF1$Tumor_Barcode = str_replace(DF1$Tumor_Barcode, 'MEL', 'sample')

  Tumor_Barcode    Sex
1      sample-1   Male
2     sample-11   Male
3     sample-12 Female
4     sample-13   Male
Nad Pat
  • 3,129
  • 3
  • 10
  • 20