[英]Why does gsub not work as expected
I have this string: 我有这个字符串:
c <- "thethirsty thirsty itthirsty (thirsty) is"
I want the output to be as 我希望输出为
"thethirsty thirsty itthirsty no is"
This is what I am trying. 这就是我正在尝试的。
gsub(" (thirsty) ", " no ", c)
This is what I am getting. 这就是我得到的。 Why does not it work?
为什么不起作用? And suggest an alternative to do this.
并提出替代方法。
"thethirsty no itthirsty (thirsty) is"
By default gsub
interprets the first parameter as a regular expression. 默认情况下,
gsub
将第一个参数解释为正则表达式。 You don't want that and should set fixed=TRUE
: 您不需要这样做,应该将
fixed=TRUE
设置fixed=TRUE
:
gsub(" (thirsty) ", " no ", c, fixed=TRUE)
#[1] "thethirsty thirsty itthirsty no is"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.