NBA (Daniel Brooks)

Do to my love of sports, I founf the franchise wins for each NBA basketball team from 1946-2015:

http://www.basketball-reference.com/leagues/NBA_wins.html

Analysis:

  1. Most overall wins in franchise history of the lifetime of the NBA/BBA

  2. Most wins by a team over the time span

  3. Most wins by a team by year

library(dplyr)

get_base_data <- function(){
  nba_df <- read.csv("leagues_NBA_wins_active.csv", header = TRUE, sep = ",") %>%
    filter(Rk != 'Rk', Season != 'Total')
  # take the dasehs out - this is going to have to be a matrix at some point later...
  nba_df$Season <- gsub("-", "", nba_df$Season)
  return (nba_df)
}

get_winners <- function(subset_df){
  the_teams_names <- colnames(subset_df)
  mtrx <- matrix(as.numeric(unlist(subset_df)),nrow=nrow(subset_df))
  df <- as.data.frame(colSums(mtrx))
  colnames(df) <- c("wins")
  df$team <- the_teams_names
  head(arrange(df, desc(wins)), n=10)
}

most_wins_total <- function(){
  get_base_data() %>% 
    subset(select = -c(Rk,Season,Lg)) %>% 
    get_winners()
}

most_wins_for_interval <- function(start_season, end_season){
  start_season <- gsub("-", "", start_season)
  end_season <- gsub("-", "", end_season)

  get_base_data() %>% 
    subset(select = -c(Rk,Lg)) %>% 
    filter(Season >= start_season & Season <= end_season) %>% 
    subset(select = -c(Season)) %>% 
    get_winners()
}

most_wins_for_specific_season <- function(season){
  most_wins_for_interval(season, season)
}

Most Wins:

most_wins_total()
##    wins team
## 1  2217  BOS
## 2  2204  LAL
## 3  2040  PHI
## 4  1725  DET
## 5  1703  NYK
## 6  1588  GSW
## 7  1475  PHO
## 8  1470  SAC
## 9  1452  SAS
## 10 1433  CHI

Most wins by a team over the time span

most_wins_for_interval('1990-91', '1999-00')
##    wins team
## 1   471  UTA
## 2   405  CHI
## 3   400  SAS
## 4   386  OKC
## 5   341  PHO
## 6   320  DEN
## 7   318  MIA
## 8   308  LAL
## 9   308  POR
## 10  306  NYK

Most wins by a team by year

# Lakers went 63-19 in 89-90
most_wins_for_specific_season('1989-90')
##    wins team
## 1    62  CHI
## 2    62  UTA
## 3    61  SAC
## 4    58  MIA
## 5    58  ORL
## 6    50  LAL
## 7    47  DET
## 8    47  POR
## 9    45  PHO
## 10   41  MIN