Skip to content

Instantly share code, notes, and snippets.

View jalapic's full-sized avatar

James Curley jalapic

View GitHub Profile
library(tidyverse)
library(magrittr)
library(rvest)
webpage <- read_html("https://en.wikipedia.org/wiki/List_of_tournament_performances_by_Tiger_Woods")
l <- webpage %>% html_nodes("table.wikitable") %>% html_table()
@jalapic
jalapic / gist:a3ae8d96684efe847bfddeee1a256b85
Created December 30, 2018 18:55
17 consonants out of scrabble tile distribution
## Drawing consonants in a row
tiles <- c(rep("V", 44), rep("C", 56)) # 42 vowels + 2 blanks, 56 consonants
# combined vowels and blanks into "V" as don't care about difference for this
# loop 1 million times
res<-NULL
for(i in 1:1000000){
draw <- sample(tiles, 17, F)
@jalapic
jalapic / gist:e9ede23a3849c2d012690842e98f09cc
Created April 17, 2018 17:03
top tier point differences
library(engsoccerdata)
library(tidyverse)
england %>%
filter(tier==1) %>%
split(.$Season) %>%
map(function(x) maketable_eng(x, Season = x$Season[1], tier=1, penalties=T) ) %>%
map(~summarise(., diff = Pts[Pos==1] - Pts[Pos==2])) %>%
bind_rows %>%
ggplot(aes(x=diff))+geom_histogram(color='black', fill="gray62", binwidth = 1) + scale_x_continuous(breaks = seq(0,20,2)) +
@jalapic
jalapic / lifeExp.csv
Created February 7, 2018 20:13
Life Expectancy in 2007
country lifeExp
Afghanistan 43.828
Albania 76.423
Algeria 72.301
Angola 42.731
Argentina 75.32
Australia 81.235
Austria 79.829
Bahrain 75.635
Bangladesh 64.062
@jalapic
jalapic / gist:bb5223a74c95a1e2478c607cf19c6773
Created May 21, 2017 18:44
6 goals in consecutive away games
library(tidyverse)
library(engsoccerdata)
england %>%
filter(tier==1) %>%
homeaway() %>%
group_by(team) %>%
arrange(Date) %>%
filter(venue=="away") %>%
mutate(gameno = row_number())%>%
@jalapic
jalapic / .block
Last active April 14, 2017 04:12
Stretched Chord Diagram - From educations to occupations
license: mit
### Comparing Arsenal Points per N games over time
library(engsoccerdata)
library(tidyverse)
rollpts <- function(teamname=NULL, N=10){
rbind(england,england_current()) %>%
homeaway() %>%
filter(team==teamname) %>%
mutate(pts = ifelse(gf>ga, 3, ifelse(gf<ga, 0, 1)),
@jalapic
jalapic / .block
Last active April 11, 2017 03:40
Find geodesic distances
license: mit
@jalapic
jalapic / compete_extra.R
Last active May 18, 2017 15:43
Functions for analyzing mouse hierarchy data
expandrows <- function(df){
library(splitstackshape)
library(data.table)
temp <- cSplit(cSplit(cbind(id = 1:nrow(df), df),
"Actor", ",", "long"),
"Recipient", ",", "long")
@jalapic
jalapic / mousedata.csv
Created February 22, 2017 17:59
Example Mouse Data
Timestamp Actor Behavior Recipient Location Observer Notes
10/14/2014 11:57:16 Start Start Start Start CW NA
10/14/2014 12:03:10 6 Mounting 10 NB4 CW NA
10/14/2014 12:04:16 6 Fighting 5 NB5 CW NA
10/14/2014 12:19:27 3 Fighting 4 ML CW NA
10/14/2014 12:28:05 4 Subordinate 10 LL CW NA
10/14/2014 12:30:49 4 Fighting 2 NB1 CW NA
10/14/2014 12:34:39 4 Fighting 2 NB5 CW NA
10/14/2014 12:40:36 4 Subordinate 1 NB5 CW NA
10/14/2014 12:44:08 4 Chasing 11 LL, LR CW NA