I have the following data:
gene_Id <- c( 'No_id' , 'P1_1_EXN' , 'P1_2_EXN' ,
'P1_1_EXN_O' , 'P1_2_EXN_O' ,
'P2_1_EXN' , 'P2_2_EXN' ,
'P2_1_EXN_O' , 'P2_2_EXN_O' ,
'P1nM1' , 'P2nM1')
Count_F <- c(rep('KL',5),rep('KD',6))
DF <- data.frame(gene_Id , Count_F)
I would like to create three additional columns:
first_one should replace the cells which have the pattern
'_Number_' with
'gene_'Number' for example
replace
P1_1_EXN with gene_1 , with possibility to control the name of the rest strings that don't match this criterion. also extract the rest of the string after the pattern '_Number_' like:
taking only EXN in the previous example, and put that in second_one .
third_one should replace any cell which has 'P Number' with
'PREP Number' for example replace P1_1_EXN with PREP _1
EDIT: this is the expected output.
PRER <- c ( 'No_P' ,rep('PREP_1' , 4) , rep('PREP_2' , 4) , 'PREP_1' , 'PREP_2')
Gene_Num <- c ('No_num' , 'gene_1' , 'gene_2' , 'gene_1' , 'gene_2' ,'gene_1',
'gene_2', 'gene_1', 'gene_2' , 'NEG' , 'NEG')
Rest <-c('No_rest','EXN','EXN','EXN_O','EXN_O','EXN','EXN','EXN_O','EXN_O', 'Neg','Neg')
New_DF <- cbind(DF,Gene_Num,Rest,PRER)
Thanks a lot in advance.
'P1nM1'and'P2nM1?