2017-10-10 13 views
0

私はデータフレームに列の1つを持っていますが、5番目の区切り記号 "。"の前に文字列の一部を削除したいと思います。最後の "。" .txtと私はそれを行う方法を知らない。R区切り文字の前に文字列を削除します

入力:

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 

所望の出力:

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 

私が試した: sapply(strsplit(as.character(DFます$ V1)を、)、 '['、1 "" :5)

アドバイスをしてください。ありがとうございました。彼らは.txtを持つすべてのエンドは、あなたが行うことができれば、テキストが

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

答えて

0

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

に固定されていると仮定すると

関連する問題