【发布时间】:2017-06-09 09:17:37
【问题描述】:
在 R 中,我的字符串看起来像:
test <- 'ZYG11B|79699'
我只想保留'ZYG11B'。
我最好的尝试:
gsub ("|.*$", "", test) # should replace everything after '|' by nothing
但返回
> [1] ""
我该怎么做?
【问题讨论】:
-
只需转义
|,即gsub ("\\|.*$", "", test)