0

I want to substitute " (log2)" from "ETS2 (log2)" but the command I am using is substituting the "2" from "ETS2" as well.

Create character string

t = as.character("ETS2 (log2)")
t2 = as.character("ETS1 (log2)")

This is the code I tried.

    #for t1
    gsub("[ (log2)]", "", t)
    str_replace_all(t, "[[ (log2)]]", "")
    #for t2
    gsub("[ (log2)]", "", t2)
    str_replace_all(t2, "[[ (log2)]]", "")

Output:

    #for t1
    "ETS "
    "ETS "
    #for t2
    "ETS1 "
    "ETS1 "

Desired output:

    #for t1
    "ETS2 "
    "ETS2 "
    #for t2
    "ETS1 "
    "ETS1 "
Rashedul Islam
  • 879
  • 1
  • 10
  • 23

0 Answers0