Search code examples
rtabularsummary

Creating Summary Table from R Variables


I am currently importing a large .csv file of NBA box score summaries. Each player for each game has its own entry.

I am using the following code to calculate a few different statistics for each unique name within the .csv file.

NBA_SD <- NBA %>%
group_by(First..Last) %>%
summarise(sd = sd(DKP))

NBA_MAX <- NBA %>%
group_by(First..Last) %>%
summarise(max = max(DKP))

NBA_MIN <- NBA %>%
group_by(First..Last) %>%
summarise(min = min(DKP))

NBA_MEAN <- NBA %>%
group_by(First..Last) %>%
summarise(mean = mean(DKP))

My goal from here is to essentially create a table similar to an Excel spreadsheet with each player name and then the corresponding statistic to the right of the name in a new column.

Any help would be greatly appreciated!


Solution

  • You can create multiple summary statistics with summarise, all on the same data frame:

    library(tidyverse)
    
    NBA %>%
      group_by(First..Last) %>%
      summarise(sd = sd(DKP),
                max = max(DKP),
                min = min(DKP),
                mean = mean(DKP))