This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start_time: %Y-%m-%dT%H:%M:%SZ | |
# end_time: %Y-%m-%dT%H:%M:%SZ | |
# needs jsonlite and httr | |
# next_token can be obtained from meta$next_token to paginate through results | |
get_tweets <- function(q="",n=10,start_time,end_time,token,next_token=""){ | |
if(n>500){ | |
warning("n too big. Using 500 instead") | |
n <- 500 | |
} | |
if(n<5){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Recreation of https://twitter.com/stevenstrogatz/status/1295915404574040065/photo/1 | |
library(tidyverse) | |
library(Polychrome) | |
fun <- function(x){ | |
n <- c() | |
i <- 2 | |
r <- x | |
while(prod(n)!=x){ | |
if(!r%%i) {n=c(n,i);r=r/i;i=1} | |
i <- i+1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ggforce) | |
d <- tibble(x = c(1, 6, 10, 23,18), xpred = c(4, 8, 11, 2,22), y = 1:5, id = factor(1:5)) | |
n <- nrow(d)+1 | |
time_angle <- tibble(hour=1:24,angle=0.25*60*hour) | |
d$start <- time_angle$angle[d$x]*pi/180 | |
d$end <- time_angle$angle[d$xpred]*pi/180 | |
d$r <- d$y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lissajou <- function(a,b,delta){ | |
t <- seq(0,2*pi,0.01) | |
x <- sin(a*t+delta) | |
y <- sin(b*t) | |
tibble(x,y) | |
} | |
# setup parameters ---- | |
n <- 7 | |
params <- tibble(a=sample(1:10,n,replace = FALSE), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pyramid <- function(ymax=5,mcol="#CD3333",xoffset=0){ | |
f <- function(a,b,y){ | |
(y-b)/a | |
} | |
a1 <- ymax/0.65 | |
b1 <- 0 | |
c1 <- -ymax/(1-0.65) | |
d1 <- -c1 | |
a2 <- -ymax/(1-0.65) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
library(tidyverse) | |
library(gganimate) | |
library(extrafont) | |
loadfonts() | |
get_season <- function(x){ | |
url <- paste0("https://www.basketball-reference.com/leagues/NBA_",x,"_totals.html") | |
url %>% | |
read_html() %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(gganimate) | |
ascii <- c(";", ":", "!", "?", ".", "'", "\"", "(", ")", "[", "]", "{", | |
"}", "@", "*", "/", "\\", "&", "#", "%", "`", "^", "+", "<", | |
"=", ">", "|", "~", "$", "0", "1", "1", "10", "2", "2", "3", | |
"3", "4", "4", "5", "5", "6", "6", "7", "7", "8", "8", "9", "9", | |
"a", "a", "A", "b", "b", "B", "c", "c", "C", "d", "d", "D", "e", | |
"e", "E", "f", "f", "F", "g", "g", "G", "h", "h", "H", "i", "i", | |
"I", "j", "j", "J", "k", "k", "K", "l", "l", "L", "m", "m", "M", | |
"n", "n", "N", "o", "o", "O", "p", "p", "P", "q", "q", "Q", "r", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id | home | away | |
---|---|---|---|
1 | 3-2-2-2-1 | 4-2-2-1-1 | |
1 | P. Cech | Vardy | |
1 | Holding | Okazaki | |
1 | Monreal | Albrighton | |
1 | Kolasinac | Mahrez | |
1 | Elneny | Ndidi | |
1 | G. Xhaka | M. James | |
1 | Bellerin | Fuchs | |
1 | Oxlade-Chamberlain | Maguire |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(igraph) | |
library(smglr) | |
library(tidyverse) | |
library(ggraph) | |
g <- sample_islands(9,40,0.2,10) | |
g <- simplify(g) | |
V(g)$grp <- rep(1:9,each=40) | |
el <- get.edgelist(g) | |
E(g)$col <- case_when( | |
V(g)$grp[el[,1]]==1 & V(g)$grp[el[,2]] == 1 ~ 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
library(tidyverse) | |
# helper functions | |
get_theo_refs_cache <- function(url){ | |
doc <- read_html(url) | |
caps <- doc %>% html_nodes("caption") %>% html_text() | |
skippy <- (any(caps=="Hypothesis" | caps=="Hypotheses"))+0 | |
refs <- doc %>% | |
html_table() %>% |