【发布时间】:2018-08-04 15:33:47
【问题描述】:
我有一个特定单词列表来删除句子列表。我是否必须遍历列表并将函数应用于每个正则表达式,或者我可以以某种方式一次调用它们?我试图用 lapply 这样做,但我希望能找到更好的方法。
string <- 'This is a sample sentence from which to gather some cool
knowledge'
words <- c('a','from','some')
lapply(words,function(x){
string <- gsub(paste0('\\b',words,'\\b'),'',string)
})
我想要的输出是:
This is sample sentence which to gather cool knowledge.
【问题讨论】: