J'essaie de remplacer les deux "st". et "ste". avec "st". Il semble que ce qui suit devrait fonctionner, mais il ne fonctionne pas:
require("stringr")
county <- c("st. landry", "ste. geneveve", "st. louis")
str_replace_all(county, c("st\\.", "ste\\."), "st")
Vous pouvez utiliser |
pour signifier "ou"
> str_replace_all(county, "st\\.|ste\\.", "st")
[1] "st landry" "st geneveve" "st louis"
Ou en base 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"