library(dplyr) fast3PRanking <- function(games, ppw = 3, ppd = 1, ppl = 0) { ranking <- as.data.frame( games %>% mutate(Team = HomeTeam, GamePoints = (FTHG>FTAG)*ppw + (FTHG==FTAG)*ppd + (FTHG% bind_rows(games %>% mutate(Team = AwayTeam, GamePoints = (FTHGFTAG)*ppl)) %>% arrange(Date) %>% group_by(Team) %>% mutate(Points = cumsum(GamePoints)) %>% select(Date, Team, Points)) points <- ranking %>% group_by(Team) %>% summarise(Points = last(Points)) %>% arrange(desc(Points)) return(list(ranking,setNames(points$Points, points$Team))) }