使用gsub从R字符串上卸下/更换支架 [英] Removing/replacing brackets from R string using gsub
本文介绍了使用gsub从R字符串上卸下/更换支架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用gsub从我的字符串中删除或替换括号("或)".但是,如下所示,它不起作用.可能是什么原因?
I want to remove or replace brackets "(" or ")" from my string using gsub. However as shown below it is not working. What could be the reason?
> k<-"(abc)"
> t<-gsub("()","",k)
> t
[1] "(abc)"
推荐答案
使用正确的正则表达式有效:
Using the correct regex works:
gsub("[()]", "", "(abc)")
其他方括号表示匹配其中的任何字符" .
这篇关于使用gsub从R字符串上卸下/更换支架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文