sub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) > text<-c("Hello Adam! Hello Ava!") > sub(pattern="Adam|Ava",replacement="world", text) #只做一次替换(不管有几次匹配) [1] "Hello world! Hello Ava!" > gsub(pattern="Adam|Ava",replacement="world", text) #满足条件的匹配都做替换 [1] "Hello world! Hello world!" > text #原字符串并没有改变 [1] "Hello Adam! Hello Ava!"