R 相交字符串 [英] R intersecting strings

查看:46
本文介绍了R 相交字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以以下数据为例:

 basketball = c("MISS W. Johnson 18' Pullup Jump Shot",
                "MISS Barnes 12' Pullup Jump Shot",
                "MISS Carter  19' Pullup Jump Shot")

我如何找到最常见的单词或将它们交叉"起来,以便我只得到 "MISS Pullup Jump Shot" 作为结果?

How do I find the most common words or 'intersect' them so that I will only have "MISS Pullup Jump Shot" as the result?

推荐答案

这可行,但鉴于您的问题有点含糊,我不确定它的稳健性.

This works, but I'm not sure how robust it is given your question is a little vague.

Reduce(intersect, strsplit(basketball," "))
#[1] "MISS"   "Pullup" "Jump"   "Shot"

这篇关于R 相交字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆