Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在R中消除部分字符串。字符串如下
“ENSG00000003137 |2 |CYP26B1 |72356367 |72359355”
我希望得到的字符串是
“|2 |CYP26B1 |72356367 |72359355”
尝试以下操作:
substr(s, regexpr("\\|", s), nchar(s)) # [1] "|2 |CYP26B1 |72356367 |72359355"
s你的字符串在哪里
s
(a)regexpr查找|字符串中第一个的出现。 (b)nchar计算字符串的总长度(以字符为单位), substr然后从 (a) 到 (b) 获取子字符串
regexpr
|
nchar
substr