Skip to content

Instantly share code, notes, and snippets.

let
Source = Excel.CurrentWorkbook(){[Name=Table]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Person", type text}, {"City", type text}, {"Index", type text}, {"Percentage", Int64.Type}, {"Application Date", type date}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Index]), "Index", "Percentage", List.Sum),
#"Demoted Headers" = Table.DemoteHeaders(#"Pivoted Column"),
#"Kept First Rows" = Table.FirstN(#"Demoted Headers",1),
#"Transposed Table" = Table.Transpose(#"Kept First Rows"),
#"Changed Type1" = Table.TransformColumnTypes(#"Transposed Table",{{"Column1", Int64.Type}}),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Changed Type1", {"Column1"}),
#"Transposed Table1" = Table.Transpose(#"Removed Errors"),
let
Source = Excel.CurrentWorkbook(){[Name=Table]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Person", type text}, {"City", type text}, {"Index", type text}, {"Percentage", Int64.Type}, {"Application Date", type date}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Index]), "Index", "Percentage", List.Sum),
#"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"1", type text}, {"2", type text}, {"3", type text}}),
#"Merged Columns" = Table.CombineColumns(#"Changed Type1", {"1", "2", "3", "4"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged"),
#"Trim Text" = Table.AddColumn(#"Merged Columns", "Percentages", each Text.TrimEnd([Merged], ","), type text),
#"Removed Columns" = Table.RemoveColumns(#"Trim Text",{"Merged"})
in
#"Removed Columns"
##Load Packages
library(tidyverse)
library(rpart)
library(rpart.plot)
##Manipulate
model_data <- dataset
##Create Categorical
pp90_bin <- cut(model_data$points_per_90,
model_data <- dataset
fantasy_lm <- lm(points_per_90 ~ now_cost + goals_scored + assists + clean_sheets, data = model_data)
model_data$score_lm <- predict(fantasy_lm, model_data)
##Load Packages needed to run the R code
library(readxl)
library(tidyverse)
##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)
@FthrsAnalytics
FthrsAnalytics / Data Connector
Last active July 5, 2018 23:05
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 %>%
@FthrsAnalytics
FthrsAnalytics / R Series - Introduction
Created May 4, 2018 03:00
R Series - Introduction
Feathers <- 7
Analytics <- 4
Feathers + Analytics
feathers_analytics <- 'new object'
feathers_analytics
{
"name":"Feathers Analytics Theme",
"background":"#E7E7E7",
"foreground":"#44546A",
"tableAccent":"#2EB2FF",
"dataColors":["#44546A","#2EB2FF","#FF2EA4"]
}
{
"name":"Feathers Analytics Theme",
"background":"#E7E7E7",
"foreground":"#44546A",
"tableAccent":"#2EB2FF",
"dataColors":["#44546A","#2EB2FF","#FF2EA4"],
"visualStyles":{
"*":{
"*":{
"*":[{