0

I am analyzing the NBA dataset based on players from the 2011 to 2017 season. This dataset contains information like game, points, assist, etc. My current dataset looks something like this: enter image description here

As you can see that, Rafer Alston appears three times, and PTS, TRB, and AST all reflect on his average stats during that season.

Question: Is there a way to combine these three rows into one row by summing PTS, TRB, and AST, and then dividing by three in R?

My initial thought is running the code below:

unique_player <- nba%>%group_by(Player)%>%tally()

So we can see how many times do each player appear:

enter image description here

Red Sus
  • 11
  • 2
  • What you want is basically mean of all those columns for each player. Try : `nba%>% group_by(Player) %>% summarise(across(PTS:AST, mean, na.rm = TRUE))` – Ronak Shah Dec 11 '20 at 09:19
  • maybe something like `df %>% pivot_longer(cols = all_of(c("PTS", "TRB", "AST")), names_to = "variables", values_to = "perfs") %>% group_by(Player) %>% summarise(mean_perf = mean(perfs))`. Using packages `dplyr` and `tidyr`. This is if you want to summarize other all 3 variables. Otherwise Ronak Shah comment is more relevant. – Paul Dec 11 '20 at 09:20

0 Answers0