[英]check if all words present in a sentence
I am trying to get the output from words_check only if all the words in variable 'words' present in word_check.仅当 word_check 中存在变量“words”中的所有单词时,我才尝试从 words_check 获取输出。
I am trying to retrieve output from word_check.我正在尝试从 word_check 检索输出。
My below code is not returning any value.我下面的代码没有返回任何值。 Please help!
请帮忙!
words <- "battery on key issue"
word_check <- c("battery on","key issue","battery on key issue")
pr_wd <- word_check[all(strsplit(word_check," ") %in% strsplit(words," "))]
"battery on key issue"
I think this works, but it would be nice to have a couple other examples to test on.我认为这行得通,但最好有几个其他示例来测试。
word_check[unlist(Map(strsplit(words," "), strsplit(word_check," "), f = function(x, y) all(x %in% y)))]
#[1] "battery on key issue"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.