Basketball Fantasy Rankings (2022-23)

Basketball Fantasy Rankings (2022-23)

Library

These contain the packages that are needed.

library(readxl) # Reading Excel Files
library(tidyverse) # Data Manipulation
library(janitor) # Cleaning Data
library(ggpubr) # Publication Ready Plots

Fantasy Rankings

Getting my Fantasy Rankings for the Year. Find the website Hier. First step is to load in the excel file and clean the column names with the janitor package. I then create a few new rows that contain the total points and the rankings for this variable.

file_name <- "fantasy_rankings_2023.xlsx"
df <- read_excel(file_name) %>% clean_names()
df$rank_average <- seq.int(nrow(df)) 
df$total_points <- df$total * df$gp
df$rank_total <- rank(-df$total_points, ties.method = "min")

Draft Order

Our Draft order (taken from ESPN), first step is to load in this excel.

draft_order <- "draft_order_2023.xlsx"
df2 <- read_excel(draft_order)
df2$draft_order <- seq.int(nrow(df2))

Cleaning Data

Selecting which columns and the order. Also fixing a players name.

df2$name <- sub("^([[:alpha:]'-]+\\.?\\s+[[:alpha:]'-]+(?:\\s+Jr\\.)?).*,.*$", "\\1", df2$Player)
df2$name[91] <- "O.G. Anunoby"
names(df)[names(df) == "total"] <- "average"
colsdf <- c(2,3,18,17,19,6:16)
colsdf2 <- c(2,3)

df1_fin <- df[, colsdf]
df2_fin <- df2[, colsdf2]

Merging Datasets

completed <- merge(df1_fin, df2_fin, by="name", all.x = TRUE)
completed$diff_average <- completed$rank_average - completed$draft_order
completed$diff_total <- completed$rank_total - completed$draft_order
#write.csv(completed, "rankings.csv") # Writing as a CSV file.

Excel files found Hier.