Skip to content

Instantly share code, notes, and snippets.

@Torvaney
Torvaney / premier_league_xg.csv
Created July 14, 2018 08:49
Premier League shot xGs 2014/15 -> 2017/18
We can't make this file beautiful and searchable because it's too large.
match_id,date,home,away,hgoals,agoals,side,xg,league,season
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.01874101348221302,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.015597633086144924,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.06492315977811813,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.057787537574768066,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.0488010048866272,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.03097105398774147,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.02559618093073368,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.06947857141494751,EPL,2014
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.5765787363052368,EPL,2014
@Torvaney
Torvaney / hillary.R
Last active July 13, 2018 13:58
is both a boy and a girls name
# install.packages("babynames")
library(babynames)
babynames %>%
filter(str_detect(name, "Hill?ary")) %>%
count(year, sex, wt = prop) %>%
ggplot(aes(x = year, y = nn)) +
geom_line(aes(colour = sex)) +
scale_y_continuous(labels = scales::percent_format()) +
theme_minimal() +
@Torvaney
Torvaney / flight-delays.Rmd
Created July 1, 2018 22:24
WIP/my flight is delayed
---
title: "UK flights"
---
```{r}
library(tidyverse)
library(rvest)
```
library(tidyverse)
library(lubridate)
source("https://raw.githubusercontent.com/mjfrigaard/RDataSets/master/DotR/monarchs.R")
monarchs <-
monarchs %>%
mutate(reign_length = lubridate::interval(from, to) / years(1))
monarchs %>%
@Torvaney
Torvaney / rule-of-succession.R
Last active June 6, 2018 14:55
Visualising Laplace's rule of succession
library(tidyverse)
# CF en.wikipedia.org/wiki/Rule_of_succession
# True probabilities
true_probs <- c(0.1, 0.3, 0.7, 0.9)
# How many runs for each probability and prior?
n_repetitions <- 10
# How many observations to update estimated probability?
n_observations <- 500
@Torvaney
Torvaney / infix.clj
Created June 5, 2018 11:26
Infix functions in clojure
(defmacro $
([x] x)
([f x] `(~f ~x))
([x f & args] `(~f ($ ~x) ($ ~@args))))
;; Examples
($ 1 + 5)
; 6
($ 1 + 5 + 2)
@Torvaney
Torvaney / R-commands.md
Last active May 30, 2018 18:30
Adding special "commands" to an R session.

I recently tried hacking some custom "commands" into the R REPL. I thought the method was fun and interesting enough to be worth sharing.

Background

In other language REPLs/interactive prompts, there are often a couple of special commands. Some of the more common ones are exit (to exit the session) and clear (to clear the buffer).

I often find myself instinctively attempting to use these in R. Of course, they do not exist in R. To terminate the R session, one can use quit(...) or q(...), but this requires typing brackets, as well as a "no" if you want to avoid that annoying "save workspace?" prompt.

exit

@Torvaney
Torvaney / compound-interest.Rmd
Last active May 28, 2018 17:43
Notebook exploring compound interest
---
title: "Compound interest calculator"
---
Terms are defined as:
* Principal - Initial amount invested
* Contribution - How much is contributed in each period
* Interest - Interest rate
* Period - How frequently interest is compounded
@Torvaney
Torvaney / tools-and-stuff.md
Last active May 26, 2018 13:57
Tools and stuff I use regularly but would forget about and need to install if/when I get a new machine.