Created
February 16, 2017 04:18
-
-
Save jalapic/0b2dfc92cae8697fbd39ba9477f52cca to your computer and use it in GitHub Desktop.
HomeAwayRecords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Data from - https://github.com/jalapic/engsoccerdata | |
library(tidyverse) | |
library(engsoccerdata) | |
df <- rbind(england, england_current()) %>% | |
filter(tier==1) %>% | |
homeaway() | |
df$Date <- as.Date(as.character(df$Date)) | |
head(df) | |
df1 <- df %>% | |
group_by(team,Season) %>% | |
arrange(Date) %>% | |
mutate(gameno = row_number()) %>% | |
group_by(team,venue,Season) %>% | |
summarise(totalpts = 3*sum(gf>ga)+sum(gf==ga)) %>% | |
spread(venue,totalpts) %>% | |
mutate(totalpts = away+home, pcthome = home/totalpts) %>% | |
ungroup() %>% | |
arrange(-pcthome) | |
head(df1,10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment