首页 > 解决方案 > 如何在 R 或 sqldf 中获取部分匹配的计数

问题描述

我的数据框中有部分文本。如何获得他们的计数示例:

t=data.frame(x=c('I want to go there','I want to go here','I don't want to go'))

预期:由于前两个是部分的 - 我希望它们计为 2

标签: r

解决方案


如果我理解的很好,你要不要数一下“我要”这两个字出现了多少次。

library(stringr)
t=c('I want to go there','I want to go here',"I don't want to go")
x <- str_count(t, "I want")
print(x)

推荐阅读