【发布时间】:2019-01-22 20:26:46
【问题描述】:
我在 R 中有一个向量,它在向量的最后一个索引处有一个单词列表。我需要从该列表中删除一些单词
sentence <- "This is a sample sentence with words like or to be removed"
wordsToRemove <- c("The","an", "very", "of", "or","in","a","uses","that","be")
splitSent <- strsplit(sentence, " ")
我尝试了wordsToRemove %in% list(splitSent),但这一切都是错误的。有没有其他办法处理?
注意:这句话是我的向量中的一个元素,它有 int,其他数据类型也是如此。我已经通过下面的链接 R: find vector in list of vectors
【问题讨论】:
-
您可能需要
splitSent[[1]][!splitSent[[1]] %in% wordsToRemove]