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)
>Solution :
Using stringr
library(stringr)
df$Tumor_Barcode = str_replace(df$Tumor_Barcode, 'MEL', 'sample')
Tumor_Barcode Sex
1 sample-1 Male
2 sample-11 Male
3 sample-12 Female
4 sample-13 Male