In R, how do I sub specific character from my data?
I have this :
20220801_NM7_Chrom_2399_A12_CCIH.CSV
I want get below
20220801_NM7_Chrom_2399_CCIH
Thanks for sparing your time.
CodePudding user response:
- You can try this
x <- "20220801_NM7_Chrom_2399_A12_CCIH.CSV"
sub( "_A\\d _" , "_", sub("\\..*" , "" , x))
- Output
"20220801_NM7_Chrom_2399_CCIH"