从列表中删除其他列表在R中为TRUE/FALSE的值

从列表中删除其他列表在R中为TRUE/FALSE的值,r,list,R,List,我在处理列表时有点麻烦。我有一个包含拆分字符串的列表,我需要删除该列表中的值,而另一个列表中的相应值为FALSE 我已将我的清单定义为: string1 = "derive sic poetry nor any creative old testament the memc the" string2 = "indeed fitting that his last creative act should have been to" string3 = "expression we have of

我在处理列表时有点麻烦。我有一个包含拆分字符串的列表,我需要删除该列表中的值,而另一个列表中的相应值为
FALSE

我已将我的清单定义为:

string1 = "derive sic poetry nor any creative old testament the memc the"
string2 = "indeed fitting that his last creative act should have been to"
string3 = "expression we have of the creative and redemptive power of god"
string4 = "final trust which is the creative secret of the new race" 
string5 = "on which some day a creative belief may write her message" 

context = list(string1, string2, string3, string4, string5)
splitcontext = strsplit(fullcontext, split = ' ')
现在我的目标是消除
splitcontext
列表中的非单词。我知道这可以通过
qdapDictionaries
库来实现。在这里,我定义了一个函数来确定单词是否为英语单词的
TRUE
FALSE

library(qdapDictionaries)
is.word <- function(x) x %in% GradyAugmented
我的问题是从
splitcontext
中删除单词,其中
indicatorlist
等于
FALSE

我怎样才能做到这一点?提前非常感谢您抽出时间。这是我的有缺陷的代码——我不知道如何并行循环
indicatorlist
splitcontext

removefalse <- function(x){
  x[which(indicatorlist==TRUE)]
}
lapply(splitcontext, removefalse)

removeflse如果我们有两个
list
s值和一个对应的
logical
元素,那么使用
Map
提取与
向量的逻辑
list
中的真值对应的“值”

Map(`[`, splitcontext, indicatorlist)
但是,我们可以在不创建“指示符列表”的情况下执行此操作

lapply(splitcontext, function(x) x[is.word(x)])
数据
fullcontext什么是
fullcontext
?我想您需要
lappy(splitcontext,function(x)x[is.word(x)])
。我非常感谢你的帮助。
lapply(splitcontext, function(x) x[is.word(x)])
fullcontext <- c(string1, string2, string3, string4, string5)
splitcontext <- strsplit(fullcontext, split = ' ')