Skip to content

Instantly share code, notes, and snippets.

@jalapic
Created February 16, 2017 04:18
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 jalapic/0b2dfc92cae8697fbd39ba9477f52cca to your computer and use it in GitHub Desktop.
Save jalapic/0b2dfc92cae8697fbd39ba9477f52cca to your computer and use it in GitHub Desktop.
HomeAwayRecords
## 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