说我们有:
stringTest <- c("Here we have 4 words", "Here we have avwerfaf 4")
预期输出:
“”这里“”我们“”拥有“”单词“”这里“”我们“”拥有“” avwerfaf“
我想使用gsub(),但是其他方法绝对不包括在内。谢谢你们!
您可以使用strsplit
:
result <- unlist(strsplit(stringTest, " |\\d"))
result[result != ""]
#> [1] "Here" "we" "have" "words" "Here" "we"
#> [7] "have" "avwerfaf"
library(tidyverse)
stringTest <- c("Here we have 4 words", "Here we have avwerfaf 4")
gsub(" \\d", replacement = "", stringTest)