【发布时间】:2020-07-04 13:50:30
【问题描述】:
我有一个包含五个元素的文本向量,名为 text2。它是一个实际数据集的样本,包含 1,800 多行和多列。
我查看了 stackoverflow 中的其他代码解决方案,但找不到匹配项。
输入
text2 <- c("Ian Desmond hits an inside-the-park home run (8) on a line drive down the right-field line. Brendan Rodgers scores. Tony Wolters scores." , "Ian Desmond lines out sharply to center fielder Jason Heyward.", "Ian Desmond hits a grand slam (9) to right center field. Charlie Blackmon scores. Trevor Story scores. David Dahl scores.", "Ian Desmond homers (12) on a fly ball to center field. Daniel Murphy scores.", "Wild pitch by pitcher Jake Faria. Sam Hilliard scores.")
输出 我想知道 text2 中的哪些元素同时包含“Wild pitch”和“scores”。我想要计数和元素编号。例如, 在 text2 中只有一个元素(最后一个)是匹配的。因此,输出将包含计数 (1) 和元素编号 (5)。
代码已尝试
str_detect(text2, ("Wild pitch|scores"))
【问题讨论】: