Skip to content

Instantly share code, notes, and snippets.

Avatar

James Curley jalapic

View GitHub Profile
@jalapic
jalapic / lifeExp.csv
Created Feb 7, 2018
Life Expectancy in 2007
View lifeExp.csv
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
6 goals in consecutive away games
View gist:bb5223a74c95a1e2478c607cf19c6773
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 Apr 14, 2017
Stretched Chord Diagram - From educations to occupations
View .block
license: mit
View gist:77ca484acdf86752700fe1eb86219000
### 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 Apr 11, 2017
Find geodesic distances
View .block
license: mit
@jalapic
jalapic / compete_extra.R
Last active May 18, 2017
Functions for analyzing mouse hierarchy data
View compete_extra.R
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 Feb 22, 2017
Example Mouse Data
View mousedata.csv
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
@jalapic
jalapic / homeaway.R
Created Feb 16, 2017
HomeAwayRecords
View homeaway.R
## 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)
@jalapic
jalapic / bottom_3_at_xmas_survive.R
Created Feb 6, 2017
Bottom 3 at Christmas Survive
View bottom_3_at_xmas_survive.R
### Have bottom 3 at Christmas all survived?
library(engsoccerdata)
library(tidyverse)
df <- rbind(england, england_current()) %>% filter(tier==1)
df.seasons <- split(df, df$Season)
df.tables <- lapply(df.seasons, function(x) maketable_eng(x, tier=1, Season = x[1,2]))
df.tables <- Map(cbind, df.tables, Season=unique(df$Season))
View defendingchamps.R
library(engsoccerdata)
library(tidyverse)
## get data of all top-tier seasons
df <- rbind(england, england_current()) %>% filter(tier==1)
## Get champions from each season.
df.seasons <- split(df, df$Season)
df.tables <- lapply(df.seasons, function(x) maketable_eng(x, tier=1, Season=x[1,2]))