Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sub specific character in R

In R, how do I sub specific character from my data?

I have this :

20220801_NM7_Chrom_2399_A12_CCIH.CSV

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want get below

20220801_NM7_Chrom_2399_CCIH

Thanks for sparing your time.

>Solution :

  • You can try this
x <- "20220801_NM7_Chrom_2399_A12_CCIH.CSV"

sub( "_A\\d+_" , "_", sub("\\..*" , "" , x))
  • Output
"20220801_NM7_Chrom_2399_CCIH"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading