我从tm包中使用removewords清理样本数据,但removeWords函数连接了删除后的单词。应该是“环保死青蛙”“环保死老鼠”。有谁能给我带路吗?
library(tm)
dc<-c("environmental dead frog still","environmental dead mouse come")
manualremovelist<-c("the","does","doesn't","please","new","ok","one","cant",
"doesnt","can","still","done","will","without","seen",
"also","danfoss","case","doesn´t","due","need","occurs","made",
"using","now","make","makes","needs","put","okay","sno","since","therefore",
"found","milwaukee","probably","got","finally","isnt","per","two",
"obvious","unable","must","nos","3nos","1no",".","phone","tel","attached",
"given","find","have","see","be","give","do","come","use","make","get",
"try","call","request")
dc<-removeWords(dc,manualremovelist)
"environmentaldeadfrog" "environmentaldeadmouse"发布于 2021-07-20 16:03:02
removeWords仅适用于单词。您可以将字符串拆分成单词,并对单个短语/句子使用removeWords。
library(tm)
dc <- sapply(strsplit(dc, '\\s+'), function(x)
trimws(paste0(removeWords(x, manualremovelist), collapse = ' ')))
dc
#[1] "environmental dead frog" "environmental dead mouse"https://stackoverflow.com/questions/68451246
复制相似问题