text <- "fsfs blabla Honda t Asus"
我希望得到的結果:
[1] "Honda" "Asus"
我已經通過這個函數來完成它:
foo <- function(txt){
txtNew <- txt
txtNew2 <- txt
txtMemory <- ""
while(txtNew != txtMemory){
txtNew <- txtNew2
txtMemory <- txtNew2
txtNew <- gsub("\\s[a-z]","",txtNew)
txtNew2 <- paste0(" ", txtNew)
}
txtNew <- sub("^\\s+", "", txtNew)
strsplit(txtNew, " ")
}
foo("fsfs blabla Honda t Asus")
,但我想有更容易在R?