Я хочу удалить шаблон "-n\" из строки и заменить шаблон "\n" на пробел.
"-n\"
"\n"
Например:
"intelec-\ntual"
Должно быть:
"intelectual"
И:
"diferentes\ntipos"
"diferentes tipos"
Я пробую разные комбинации gsub, но пока не повезло. Например:
gsub("[-\n]", "", output2)
взгляните на https://regex101.com/
gsub("-?\n", "", c("intelec-\ntual", "diferentes\ntipos"))
Если вы используете решение multi gsub, вам не нужно заботиться о порядке, в котором вы выполняете замену:
h <- c("intelec-\ntual", "diferentes\ntipos") mgsub::mgsub(h, c("-\n", "\n"), c("", " ")) "intelectual" "diferentes tipos"
Вот базовое решение R
> gsub("-\n","",s1,fixed = TRUE) [1] "intelectual" > gsub("\n"," ",s2,fixed = TRUE) [1] "diferentes tipos"
Данные
s1 <- "intelec-\ntual" s2 <- "diferentes\ntipos"
Здесь вы go.
library(stringr) str_replace("diferentes\ntipos", pattern = "\\n", replacement = " ") [1] "diferentes tipos" str_remove_all("intelec-\ntual", pattern = "-\n") [1] "intelectual"