3位数字后删除字符串的一部分
我想通过在第一个3位数之后切割每个字符串来代替列表中的字符串。
a <- c("MTH314PHY410","LB471LB472","PHY472CHM141")
我希望它看起来像
a <- c("MTH314","LB471","PHY472")
我尝试过类似的东西
b <- gsub("[100-999].*","",a)
,但它返回c(“ mth”,“ lb”,“ phy”)
没有第一个数字
I would like to substitute the strings in the list by cutting each string after the first 3-digit number.
a <- c("MTH314PHY410","LB471LB472","PHY472CHM141")
I would like for it to look something like
a <- c("MTH314","LB471","PHY472")
I have tried something like
b <- gsub("[100-999].*","",a)
but it returns c("MTH","LB","PHY")
without the first number
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于
stringr :: str_remove
的可能解决方案:A possible solution, based on
stringr::str_remove
: