【发布时间】:2021-08-15 01:37:47
【问题描述】:
给定一张桌子:
| text |
|---|
| The quick brown fox jumped over the lazy dogs |
| The cow jumped over the moon |
还有一个标记和值的查找表:
| keyword | value |
|---|---|
| jumped | 2 |
| over the | -1 |
| cow | 2 |
如何在 R 中构建一个函数来有效地记录一个短语出现的次数?
理想的结果是:
| text | score |
|---|---|
| The quick brown fox jumped over the lazy dogs | 1 |
| The cow jumped over the moon | 3 |
通常我会使用 for 循环并一次遍历查找表一行,但我知道可能有更好的方法。我只是不知道它是什么。 (使用 tidyverse 的方式获得奖励积分!)
提前感谢您提供的任何链接或指导,您可以分享以提高效率!
【问题讨论】: