1

My rownames in df looks like this:

hsa-miR-20a-5p_TAAAGTGCTTATAGTGCAGGTAA_0;I-A;0;g

I would like them to look like this, space separated instead of _ and ;

hsa-miR-20a-5p TAAAGTGCTTATAGTGCAGGTAA 0 I-A 0 g

I suppose I could use gsub?

user2300940
  • 2,355
  • 1
  • 22
  • 35
  • 4
    If you, just, want to replace `_` and `;` see [here](http://stackoverflow.com/questions/11936339/in-r-how-do-i-replace-text-within-a-string) and, also, `?regex`. For no regex replacement see, also, `?chartr`; `chartr("_;", " ", "hsa-miR-20a-5p_TAAAGTGCTTATAGTGCAGGTAA_0;I-A;0;g")` – alexis_laz Jun 20 '16 at 17:49

1 Answers1

2

We can use the OR i.e | to match multiple delimiters and replace it with space " "

gsub("_|;", " ", "hsa-miR-20a-5p_TAAAGTGCTTATAGTGCAGGTAA_0;I-A;0;g")
#[1] "hsa-miR-20a-5p TAAAGTGCTTATAGTGCAGGTAA 0 I-A 0 g"

If we need to split it to parts

strsplit("hsa-miR-20a-5p_TAAAGTGCTTATAGTGCAGGTAA_0;I-A;0;g", "[_;]")[[1]]
#[1] "hsa-miR-20a-5p"          "TAAAGTGCTTATAGTGCAGGTAA" "0"                       "I-A"                     "0"                      
#[6] "g"
akrun
  • 874,273
  • 37
  • 540
  • 662