Basketball Fantasy Rankings (2023-24)
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 here. 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.
file2 <- "fantasy_stats_2024.xlsx"
df <- read_excel(file2) %>% 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.
file1 <- "2024_fantasy_draft.xlsx"
df2 <- read_excel(file1)
df2$draft_order <- seq.int(nrow(df2))
Cleaning Data
Selecting which columns and the order. Also fixing a few players’ name.
df2$name <- sub("^([[:alpha:]'-]+\\.?\\s+[[:alpha:]'-]+(?:\\s+Jr\\.)?).*,.*$", "\\1", df2$Player)
df2$name[51] <- "Alperen Sengün"
df2$name[92] <- "Nicolas Claxton"
names(df)[names(df) == "total"] <- "average"
colsdf <- c(2,3,18,17,19,6:16)
colsdf2 <- c(2,3,4)
df_fin <- df[, colsdf]
df1_fin <- df2[, colsdf2]
Merging Datasets
completed <- merge(df_fin, df1_fin, by="name", all.x = TRUE)
completed$diff_average <- completed$rank_average - completed$draft_order
completed$diff_total <- completed$rank_total - completed$draft_order
completed_ordered <- completed %>%
arrange(desc(average))
#write.csv(completed_ordered, file= "fantasy_2024_fin.csv", row.names = FALSE)
Excel Files found here.