Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何替换';(';,';)';在R中使用sub?_Regex_R - Fatal编程技术网

Regex 如何替换';(';,';)';在R中使用sub?

Regex 如何替换';(';,';)';在R中使用sub?,regex,r,Regex,R,如何使用R中的sub替换(,) 让我们将x定义为: x="abc(def" 然后,当我尝试用其他内容替换()时,会出现错误: sub("(","",x) 错误是: 'Missing')”您需要转义: > sub("\\(", "@", x) [1] "abc@def" 正如Kohske所说,您需要双重转义,但也可以使用参数fixed=TRUE: sub("\\(","",x) sub("(","",x,fixed=TRUE) 两者都给你: [1] "abcdef"

如何使用R中的sub替换

让我们将
x
定义为:

x="abc(def"
然后,当我尝试用其他内容替换
)时,会出现错误:

sub("(","",x)
错误是:

'Missing')”

您需要转义:

> sub("\\(", "@", x)
[1] "abc@def"

正如Kohske所说,您需要双重转义,但也可以使用参数
fixed=TRUE

sub("\\(","",x)
sub("(","",x,fixed=TRUE)
两者都给你:

[1] "abcdef"