Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
##Load Packages needed to run the R code
##Import Data
file_path <- ##"file path of the source Excel file/Predictive Analytics with R in Power BI.xlsx"
data_set <- read_excel(file_path) %>%
select(id, total_points, now_cost, selected_by_percent, minutes, goals_scored, assists, clean_sheets, pos)
data_set$pos <- factor(data_set$pos, levels = c("GKP", "DEF", "MID", "FWD"), ordered = TRUE)
##Manipulate Data
model_data <- data_set %>%
filter(minutes > 180) %>%
mutate(points_per_90 = total_points / minutes * 90) %>%
select(-minutes, -total_points)
##Create Clusters
fantasy_clusters <- kmeans(model_data[,2:6,8], 3)
model_data$cluster <- as.factor(fantasy_clusters$cluster)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.