【发布时间】:2019-09-17 18:43:19
【问题描述】:
我有这样的文字:
text = 'I love apple, pear, grape and peach'
如果我想知道文本是否包含apple 或pear。我可以执行以下操作并且工作正常:
str_detect(text,"apple|pear")
[1] TRUE
我的问题是,如果我想使用像 (apple OR pear) AND (grape) 这样的布尔值怎么办。
无论如何我可以把它放在str_detect()。那可能吗?
以下是不工作:
str_detect(text,"(apple|pear) & (grape)" )
[1] FALSE
我想知道这一点的原因是我想编程转换一个“布尔查询”并输入grep 或str_detect。类似:
str_detect(text, '(word1|word2) AND (word2|word3|word4) AND (word5|word6) AND .....')
AND 的数量不等......
请解决多个str_detect 的问题。
【问题讨论】: