Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R intersecting strings [duplicate]

Tags:

regex

r

intersect

I have the following data as an example:

 basketball = c("MISS W. Johnson 18' Pullup Jump Shot",
                "MISS Barnes 12' Pullup Jump Shot",
                "MISS Carter  19' 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?

like image 319
geodex Avatar asked Mar 25 '14 02:03

geodex


1 Answers

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"
like image 176
thelatemail Avatar answered Nov 15 '22 06:11

thelatemail