【发布时间】:2019-10-27 15:50:13
【问题描述】:
考虑以下数据集:
a <- c("my house", "green", "the cat is", "a girl")
b <- c("my beautiful house is cool", "the apple is green", "I m looking at the cat that is sleeping", "a boy")
c <- c("T", "T", "T", "F")
df <- data.frame(string1=a, string2=b, returns=c)
我正在尝试检测 string2 中的 string1 但我的目标不仅是检测精确匹配。我正在寻找一种方法来检测 string2 中是否存在 string1 单词,无论出现什么顺序单词。例如,字符串“my beautiful house is cool”在搜索“my house”时应返回 TRUE。
我已尝试在示例数据集上方的“返回”列中说明脚本的预期行为。
我已经尝试过 grepl() 和 str_detect() 函数,但它只适用于完全匹配。你能帮忙吗?提前致谢
【问题讨论】:
标签: r string text-mining stringr grepl