Skip to content

Instantly share code, notes, and snippets.

View JoGall's full-sized avatar

Joe Gallagher JoGall

View GitHub Profile
@JoGall
JoGall / xy_speed_pos.R
Last active October 1, 2017 17:45
Extract speed and direction from x,y-coordinates
# dataframe 'dat' w/ x,y-coords in columns 'x' and 'y' and timestamp in column, 'ts', e.g.:
library(soccermatics)
attach(tromso)
dat <- subset(tromso, id == 8)[,c(1,3:4)]
#calculate direction of each vector angle (in radians)
v <- diff(complex(real = dat$x, imaginary = dat$y))
dat$direction <- c(NA, diff(Arg(v)) %% (2*pi), NA) - pi
# calculate speed (distance / time interval)
@JoGall
JoGall / FPL_price_changes.R
Last active September 9, 2017 09:59
Compute net changes in player value for each gameweek in FPL (2016-17, 2017-18)
require(dplyr)
require(ggplot2)
# get week-by-week data for current season and last (data originally taken from official API)
d17 <- read.csv(url("https://github.com/JoGall/FantasyPL/blob/master/17-18.csv"))
d16 <- read.csv(url("https://github.com/JoGall/FantasyPL/blob/master/16-17_formatted.csv"))
# compute price changes
ss16 <- d16 %>%
group_by(player_id) %>%
@JoGall
JoGall / hoodability_set_pieces.Rmd
Last active August 7, 2017 13:56
On 'Hoodability' and conceding set piece goals
Data on set piece goals scored and conceded in 2016-17 from [here](https://objective-football.blogspot.co.uk/2016/08/201617-open-playset-piecepenalty-data.html).
---
# Get data
```{r}
library(dplyr)
library(XML)
library(RCurl)
library(engsoccerdata)