Hi everyone, I'm going a bit nuts right now, as I'm about 99% sure I've done something like this before -- but how would I go about finding the # of distinct players to which a player is "connected"?
Here's an example of the data:
# A tibble: 30 x 2
goal primary_assist
<chr> <chr>
1 Jesper Fast Filip Chytil
2 Pavel Buchnevich Mika Zibanejad
3 Brett Howden Adam McQuaid
4 Jimmy Vesey Kevin Hayes
5 Chris Kreider Brett Howden
6 Jimmy Vesey Brady Skjei
7 Pavel Buchnevich Mats Zuccarello
8 Chris Kreider Anthony DeAngelo
9 Brett Howden Mats Zuccarello
10 Brendan Smith Pavel Buchnevich
# ... with 20 more rows
So you see Jesper Fast there? He has 1 goal where the accompanying primary assist is Filip Chytil, and 1 primary assist where the accompanying goal is Kevin Hayes. Because of that, he's "connected" to 2 distinct players.
Any idea how I'd calculate this for all players? I'm pretty sure this is a tidyr
-type problem. I'd really appreciate any insight.
mydata <- structure(list(goal = c("Jesper Fast", "Pavel Buchnevich", "Brett Howden",
"Jimmy Vesey", "Chris Kreider", "Jimmy Vesey", "Pavel Buchnevich",
"Chris Kreider", "Brett Howden", "Brendan Smith", "Brady Skjei",
"Mika Zibanejad", "Chris Kreider", "Kevin Hayes", "Mika Zibanejad",
"Jimmy Vesey", "Chris Kreider", "Mika Zibanejad", "Mika Zibanejad",
"Mats Zuccarello", "Mika Zibanejad", "Mats Zuccarello", "Kevin Hayes",
"Pavel Buchnevich", "Vladislav Namestnikov", "Anthony DeAngelo",
"Ryan Spooner", "Mats Zuccarello", "Chris Kreider", "Chris Kreider"
), primary_assist = c("Filip Chytil", "Mika Zibanejad", "Adam McQuaid",
"Kevin Hayes", "Brett Howden", "Brady Skjei", "Mats Zuccarello",
"Anthony DeAngelo", "Mats Zuccarello", "Pavel Buchnevich", NA,
"Marc Staal", "Kevin Shattenkirk", "Mats Zuccarello", "Chris Kreider",
"Neal Pionk", "Neal Pionk", "Neal Pionk", "Adam McQuaid", "Neal Pionk",
"Neal Pionk", "Mika Zibanejad", "Jesper Fast", "Brendan Smith",
"Pavel Buchnevich", "Vladislav Namestnikov", "Anthony DeAngelo",
"Kevin Shattenkirk", "Brady Skjei", "Mats Zuccarello")), row.names = c(NA,
-30L), class = c("tbl_df", "tbl", "data.frame"), .Names = c("goal",
"primary_assist"))