我正在尝试替换两个“st”。和“ste”。与“圣”。似乎以下应该工作,但它没有:
require("stringr")
county <- c("st. landry", "ste. geneveve", "st. louis")
str_replace_all(county, c("st\\.", "ste\\."), "st")
你可以|
用来表示“或”
> str_replace_all(county, "st\\.|ste\\.", "st")
[1] "st landry" "st geneveve" "st louis"
或者在基础 R
> gsub("st\\.|ste\\.", "st", county)
[1] "st landry" "st geneveve" "st louis"
> A<-"this string, contains a handful of, useless: punctuation. Some are to escape. Aaargh! Some might be needed, but I want none!"
> gsub(", |: |\\. |!","",A)
[1] "this string contains a handful of useless punctuation Some are to escape Aaargh Some might be needed but I want none"