Tiebreakers

(1) Cumulative number of birdies and eagles (eagles are worth double) from all four golfers

(2) Longest Drive on the 18th hole from your Day 4 Golfer

Golfer Data

setwd("/Users/M.S.Czahor/Desktop")
wyngolf <- read.csv("wyngolf.csv")
world <- read.csv("worldranks.csv")

wyngolf$golfer <- paste(gsub(" ", "", 
                             sub('.*\\,', '',
wyngolf$wyn_golfers)),sub('\\,.*', '', wyngolf$wyn_golfers))


ids <- intersect(wyngolf$golfer,as.character(world$golfer))

Top 20 Golfers in Tournament Based on World Rankings

top20 <- world[world$golfer %in% ids,]
top20 <- top20[1:20,]

Team Names

teams <- c("Breden","Brian Moore","Cam","Carl",
           "Charlie","Finnis","Kyle","Matt",
           "Michael","Sumski","TRauth","Weaver")

Assign Golfer

##Random Numbers Selected by Last Year's Champ -- The Moose##
library(pander)
set.seed(47)
day1_golfer <- sample(top20$golfer,12) ###Assign Day 1 Golfers  Thursday August 16th 

set.seed(937)
day2_golfer <- sample(top20$golfer,12) ###Assign Day 2 Golfers  Friday August 17th 

day3 <- read.csv("day3_golfers.csv")   ##TOP 12 IN TOURNAMENT REMAINING

##Assign Day 3 Golfers  Saturday August 18th ... Wait until after cut

##Assign Day 4 Golfers  Sunday August 19th ... Wait until after cut

Create Scoreboard

scoreboard <- data.frame(teams,day1_golfer,day2_golfer)
scoreboard$day3_golfer <- "TBD"
set.seed(47)
scoreboard$day3_golfer <- sample(day3$golfer,12) 
scoreboard$day4_golfer <- scoreboard$day3_golfer

scoreboard$day1_score <- 0
scoreboard$day2_score <- 0
scoreboard$day3_score <- 0
scoreboard$day4_score <- 0
scoreboard$total_score <- 0
scoreboard$projected_pick <-0

Scrape Live Data

library(magrittr)
library(rvest)
## Loading required package: xml2
library(XML)
## 
## Attaching package: 'XML'
## The following object is masked from 'package:rvest':
## 
##     xml
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
url <- "https://www.msn.com/en-us/sports/golf/leaderboard" 
page <- read_html(url) #Creates an html document from URL
table <- html_table(page, fill = TRUE) #Parses tables into data frames

table <- table[[2]]
table$Name[which(table$Name=="Si Woo Kim")] <- "Siwoo Kim"

allgolfers <- c(as.character(scoreboard$day1_golfer),as.character(scoreboard$day2_golfer),as.character(scoreboard$day3_golfer),as.character(scoreboard$day4_golfer))

golf_ids <- intersect(allgolfers,table$Name)

table <- table[table$Name %in% golf_ids,]
scoreboard$total <- 0

for(i in 1:12){
  
  scoreboard$day1_score[i] <-  table$R1[which(table$Name==scoreboard$day1_golfer[i])]
  scoreboard$day2_score[i] <-  table$R2[which(table$Name==scoreboard$day2_golfer[i])]
  scoreboard$day3_score[i] <-  table$R3[which(table$Name==scoreboard$day3_golfer[i])]
  scoreboard$day4_score[i] <-  table$R4[which(table$Name==scoreboard$day4_golfer[i])]

}

scoreboard$total <- scoreboard$day1_score+as.numeric(scoreboard$day2_score)+as.numeric(scoreboard$day3_score)+as.numeric(scoreboard$day4_score)

day12_golfer <- data.frame(paste(scoreboard$teams,"--",scoreboard$day1_golfer,"--",scoreboard$day2_golfer,"--",scoreboard$day3_golfer,"--",scoreboard$day4_golfer),scoreboard$day1_score,scoreboard$day2_score,scoreboard$day3_score,scoreboard$day4_score,scoreboard$total)
colnames(day12_golfer) <- c("team","r1","r2","r3","r4","total")
print("Sunday 8-19-18")
## [1] "Sunday 8-19-18"
day12_golfer <- day12_golfer[order(day12_golfer$total,decreasing =FALSE ),]
day12_golfer<-rbind(day12_golfer[1:5,],day12_golfer[7,],day12_golfer[6,],day12_golfer[8:12,])
pander(day12_golfer)
  team r1 r2 r3 r4 total
3 Cam – Brandt Snedeker – Shane Lowry – Doug Ghim – Doug Ghim 59 69 69 66 263
1 Breden – Harold Varner III – Julian Suri – Henrik Stenson – Henrik Stenson 66 66 70 64 266
9 Michael – Ryan Moore – Henrik Stenson – Trey Mullinax – Trey Mullinax 63 65 68 70 266
11 TRauth – Henrik Stenson – Matthew Fitzpatrick – D.A. Points – D.A. Points 68 67 68 67 270
6 Finnis – Brendan Steele – Joaquin Niemann – Nick Taylor – Nick Taylor 70 69 70 63 272
10 Sumski – Shane Lowry – Steve Stricker – Abraham Ancer – Abraham Ancer 69 69 64 71 273
5 Charlie – Jason Dufner – Daniel Berger – Jonathan Byrd – Jonathan Byrd 66 71 67 69 273
8 Matt – Daniel Berger – Brandt Snedeker – Sergio Garcia – Sergio Garcia 70 67 67 70 274
2 Brian Moore – Siwoo Kim – Ryan Moore – Harris English – Harris English 73 70 67 68 278
7 Kyle – Matthew Fitzpatrick – Hideki Matsuyama – Keith Mitchell – Keith Mitchell 70 68 69 71 278
4 Carl – Steve Stricker – Webb Simpson – Scott Brown – Scott Brown 70 68 70 71 279
12 Weaver – Julian Suri – Ollie Schniederjans – Aaron Baddeley – Aaron Baddeley 71 73 70 66 280