library(tidyverse) library('dplyr') Home_summary <- FullEPL %>% group_by(Seasons,Home) %>% summarise(Goals = sum(FTHomeGoals), Shots_on_target = sum(HomeShotsOnTarget)) Away_summary <- FullEPL %>% group_by(Seasons,Away) %>% summarise(Goals = sum(FTAwayGoals), Shots_on_target = sum(AwayShotsOnTarget)) Total_summary <- bind_rows(Home_summary %>% rename("Team" = "Home") %>% mutate(Home_Away = "home", .after = "Team"), Away_summary %>% rename("Team" = "Away") %>% mutate(Home_Away = "away", .after = "Team")) %>% arrange(Seasons, Team, Home_Away) Final <- Total_summary %>% group_by(Team, Seasons) %>% summarise(TotalGoals = sum(Goals), TotalShotsOnTarget = sum(Shots_on_target))