R intersecting strings [duplicate]
Asked Answered
F

1

6

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?

Freidafreight answered 25/3, 2014 at 2:18 Comment(0)
T
14

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"
Thetes answered 25/3, 2014 at 2:21 Comment(2)
+ 1 for Reduce, hadn't seen that beforeShiverick
Well played. Reduce is a new one to me as well.Message

© 2022 - 2024 — McMap. All rights reserved.