-2

I have a dataset (QB2016) that I want to write r code that will summarize in one dataframe the number of times a player is listed as an observation but also list the "Opp" in the dataframe also.
For example from the following: enter image description here

I want to get a summary of all players with total number of observations but also list of opp.
For example: enter image description here

To get the total observation per player I use

library(dplyr)
total <- QB2016 %>%
         group_by(Player) %>%
         summarize(Total = n())

but how do I add the list of "Opp" for each player observation?

pogibas
  • 27,303
  • 19
  • 84
  • 117
  • 3
    People may have an easier time responding if you share the data you are using. You can use `dput` to do that. To keep it short, you can just share a section of your data, i.e.: `dput(head(QB2016, 20))` – dshkol Sep 21 '17 at 18:36

2 Answers2

0

You can simply add 'Opp' to the group_by. Is that what you mean? This will return the player, opponent, and how many times they have faced.

Spencer
  • 107
  • 9
0
QB2016 %>%
   group_by(Player) %>%
   summarize(Total = n(), Opp = paste(Opp, collapse = "")
Brian
  • 7,900
  • 1
  • 27
  • 41