我想用" (log2)"
代替"ETS2 (log2)"
,但是我使用的命令也是用“ 2”代替了“ ETS2”。
创建字符串
t = as.character("ETS2 (log2)")
t2 = as.character("ETS1 (log2)")
这是我尝试的代码。
#for t1
gsub("[ (log2)]", "", t)
str_replace_all(t, "[[ (log2)]]", "")
#for t2
gsub("[ (log2)]", "", t2)
str_replace_all(t2, "[[ (log2)]]", "")
输出:
#for t1
"ETS "
"ETS "
#for t2
"ETS1 "
"ETS1 "
所需的输出:
#for t1
"ETS2 "
"ETS2 "
#for t2
"ETS1 "
"ETS1 "