Search code examples
rlistdplyrsummarize

Summarizing dataset with dplyr


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?


Solution

  • QB2016 %>%
       group_by(Player) %>%
       summarize(Total = n(), Opp = paste(Opp, collapse = "")