Skip to content

Instantly share code, notes, and snippets.

@ccagrawal
Created January 13, 2016 20:32
Show Gist options
  • Save ccagrawal/8493082985cb9d84c5f1 to your computer and use it in GitHub Desktop.
Save ccagrawal/8493082985cb9d84c5f1 to your computer and use it in GitHub Desktop.
Finding consecutive seasons with an increase in Career Points / 36 Min
Player Season
Allen Iverson 2006
Amar'e Stoudemire 2005
Anthony Davis 2016
Blake Griffin 2016
Carmelo Anthony 2007
Charles Barkley 1988
Chris Mullin 1989
Chris Webber 2001
Clyde Drexler 1989
Damian Lillard 2016
David Robinson 1994
David Thompson 1978
DeMarcus Cousins 2016
Dirk Nowitzki 2006
Dominique Wilkins 1988
Dwyane Wade 2009
Earl Monroe 1969
Elgin Baylor 1961
George Gervin 1980
Gilbert Arenas 2006
Glen Rice 1997
Hakeem Olajuwon 1995
James Harden 2015
Jerry Stackhouse 2001
Jerry West 1966
John Havlicek 1971
Julius Erving 1980
Kareem Abdul-Jabbar 1972
Karl Malone 1990
Kevin Durant 2014
Kevin McHale 1987
Kobe Bryant 2006
Larry Bird 1988
LeBron James 2006
Michael Jordan 1987
Moses Malone 1982
Oscar Robertson 1964
Patrick Ewing 1990
Paul George 2016
Paul Pierce 2006
Pete Maravich 1977
Ray Allen 2007
Rick Barry 1967
Russell Westbrook 2015
Shaquille O'Neal 2000
Stephen Curry 2016
Tiny Archibald 1973
Tracy McGrady 2003
Vince Carter 2001
Wilt Chamberlain 1962
library(sportsTools)
players <- read.csv('players.csv')
players$Consecutive <- 0
players$Seasons <- 0
for (i in 1:nrow(players)) {
totals <- GetPlayerSpecificStats(players[i, 'Player'], 'totals', players[i, 'Season'])
tot.years <- totals[which(totals$Tm == 'TOT'), 'Season']
if (length(tot.years) > 0) {
totals <- totals[-which(totals$Season %in% tot.years & totals$Tm != 'TOT'), ]
}
totals$pp36 <- totals$PTS / totals$MP * 36
totals$cum.pts <- cumsum(totals$PTS) - totals$PTS
totals$cum.mp <- cumsum(totals$MP) - totals$MP
totals$cum.pp36 <- totals$cum.pts / totals$cum.mp * 36
totals$valid <- 0
totals[1, 'valid'] <- 1
totals[which(totals$pp36 > totals$cum.pp36), 'valid'] <- 1
#totals[which((totals$pp36 + 0.05) > totals$cum.pp36), 'valid'] <- 1
players[i, 'Seasons'] <- nrow(totals)
#players[i, 'Consecutive'] <- which(totals$valid == 0)[1]
players[i, 'Consecutive'] <- which(totals$valid == 0)[2]
cat(i, '\n')
}
players$Consecutive <- players$Consecutive - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment