R 删除特定字符串

R 删除特定字符串,r,R,我想删除这个字符 c(" 我用这个 df <- gsub("c/(/"", " ", df$text) 但我收到了这个错误: 错误:inliwc中意外的字符串常量开头的圆括号是regex元字符;在R中,需要使用\\: 您需要转义圆括号和引号,可以这样做: temp <- 'this is ac(" string' gsub("c\\(\"", " ", temp) #OR use single quotes in gsub #gsub('c\\("', " ", temp) #[

我想删除这个字符

c("
我用这个

df <- gsub("c/(/"", " ", df$text)
但我收到了这个错误:


错误:inliwc中意外的字符串常量开头的圆括号是regex元字符;在R中,需要使用\\:


您需要转义圆括号和引号,可以这样做:

temp <- 'this is ac(" string'
gsub("c\\(\"", " ", temp)
#OR use single quotes in gsub
#gsub('c\\("', " ", temp)
#[1] "this is a  string"
如果该模式在字符串中只出现一次,也可以使用sub

我们也可以使用sub

数据
尝试:gsubc\\\、df$text我不知道您到底想要什么,但您在代码中使用了一个附加字符。
temp <- 'this is ac(" string'
gsub("c\\(\"", " ", temp)
#OR use single quotes in gsub
#gsub('c\\("', " ", temp)
#[1] "this is a  string"
gsub('c("', " ", temp, fixed = TRUE)
sub('c[()]"', '', temp)
#[1] "this is a string"
temp <- 'this is ac(" string'