Skip to content

Instantly share code, notes, and snippets.

@FthrsAnalytics
Last active July 5, 2018 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FthrsAnalytics/40ea846ae96445eb9b39b6aaf3b83d9b to your computer and use it in GitHub Desktop.
Save FthrsAnalytics/40ea846ae96445eb9b39b6aaf3b83d9b to your computer and use it in GitHub Desktop.
Power BI & R - Data Connector
library(readxl)
library(dplyr)
library(broom)
data <- read_excel("C:/Users/jfthr/Google Drive/Feathers Analytics/R Visuals Presentation/R Visuals Power BI Fantasy.xlsx")
model_data <- data %>%
select(Player, TeamGroup, Price, Selected, Points, MP)
top_teams <- model_data %>%
filter(TeamGroup == "Top")
top_fit <- lm(Points ~ Price + Selected + MP, top_teams)
bottom_teams <- model_data %>%
filter(TeamGroup == "Bottom")
bottom_fit <- lm(Points ~ Price + Selected + MP, bottom_teams)
top_tidied <- tidy(top_fit)
bottom_tidied <- tidy(bottom_fit)
top_tidied$model <- "top"
bottom_tidied$model <- "bottom"
visual_data <- bind_rows(top_tidied, bottom_tidied)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment