2017-10-10 3 views
0

J'ai une colonne dans l'image et je voudrais supprimer une partie de la chaîne avant le 5ème délimiteur "." et le dernier "." pour .txt et je ne sais pas comment le faire.R supprimer la chaîne avant le délimiteur

Entrée:

jhu-usc.edu_GBM.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1481-05.txt 
jhu-usc.edu_BCD.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1482-05.txt 
jhu-usc.edu_LGG.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1483-05.txt 
jhu-usc.edu_LUAD.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1484-05.txt 
jhu-usc.edu_LUAD.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1485-05.txt 
jhu-usc.edu_BRCA.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1486-05.txt 
jhu-usc.edu_GBM.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1487-05.txt 
jhu-usc.edu_PRCA.HumanMethylation450.6.lvl-3.TCGA-06-5415-01A-01D-1488-05.txt 

sortie souhaitée:

TCGA-06-5415-01A-01D-1481-05 
TCGA-06-5415-01A-01D-1482-05 
TCGA-06-5415-01A-01D-1483-05 
TCGA-06-5415-01A-01D-1484-05 
TCGA-06-5415-01A-01D-1485-05 
TCGA-06-5415-01A-01D-1486-05 
TCGA-06-5415-01A-01D-1487-05 
TCGA-06-5415-01A-01D-1488-05 

J'ai essayé: sapply (StrSplit (as.character (df $ V1),), '[', 1 "" : 5)

Veuillez nous consulter. Je vous remercie.

Répondre

0

En supposant que le texte est fixé

sub(".*(TCGA[^.]+).*", "\\1", str1) 
0

S'ils se terminent tous par .txt alors vous pourriez faire

sub(".+\\.([^.]+).txt", "\\1", as.character(df$V1))