r - 为什么 str_count 不能处理多个字符串?
问题描述
我有一个带有这样文本的字符串:
Text <- c("How are you","What is your name","Hi my name is","You ate your cake")
我想要一个输出来计算单词“you”或“your”出现的次数
Text NumYou
"How are you" 1
"What is your name" 1
"Hi my name is" 0
"You ate your cake" 2
我尝试使用 str_count 函数,但它缺少“you”和“your”的出现
NumYou = str_count(text,c("you","your"))
为什么 str_count 不能正常工作?
解决方案
pattern
作为一个字符串传递。
stringr::str_count(tolower(Text),'you|your')
#[1] 1 1 0 2
推荐阅读
- python - 连接到不响应 ping 的主机
- python-3.x - 在 sklearn 分类器中调用 scipy.optimize.minimize 使其在并行作业中中断
- c++ - 继承的虚拟类的C++内存布局
- python-3.x - API响应中由字符串表示的Excel文件:如何使用python下载为文件?
- javascript - 为什么我无法恢复 div 元素的颜色?
- angular - 如果 Api 离线,则 Angular 状态为 0
- r - 相对于图中心给定点的经纬度散点图
- html - Materialise css Modal - 输入问题
- node.js - fs.writeFile 无法解析
- redis - Redis(社区):非集群复制和故障转移