This file contains 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
# somewhat hackish solution to: | |
# https://twitter.com/EamonCaddigan/status/646759751242620928 | |
# based mostly on copy/pasting from ggplot2 geom_violin source: | |
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r | |
library(ggplot2) | |
library(dplyr) | |
"%||%" <- function(a, b) { |
This file contains 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
# My (NOT WORKING) solution to day 5 Part 2 | |
library(tidyverse) | |
library(adventdrob) | |
library(intervals) | |
library(broom) | |
# Utility to turn Intervals::intervals into tibble | |
tidy.Intervals_full <- function(intervals) { | |
intervals %>% | |
as.data.frame() %>% |
This file contains 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) | |
# Data is downloaded from here: | |
# https://www.kaggle.com/c/digit-recognizer | |
kaggle_data <- read_csv("~/Downloads/train.csv") | |
pixels_gathered <- kaggle_data %>% | |
mutate(instance = row_number()) %>% | |
gather(pixel, value, -label, -instance) %>% | |
extract(pixel, "pixel", "(\\d+)", convert = TRUE) |
This file contains 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(adventdrob) | |
input <- advent_input(19, 2021) | |
beacons <- input %>% | |
filter(x != "") %>% | |
mutate(scanner = cumsum(str_detect(x, "scanner"))) %>% | |
filter(!str_detect(x, "scanner")) %>% | |
separate(x, c("x", "y", "z"), sep = ",", convert = TRUE) %>% |
This file contains 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(adventdrob) | |
# Add a value to the leftmost position in a binary tree | |
add_leftmost <- function(x, value) { | |
if (!is.list(x)) x + value | |
else list(add_leftmost(x[[1]], value), x[[2]]) | |
} | |
# Add a value to the rightmost position in a binary tree |
This file contains 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(modelr) | |
library(tidyverse) | |
library(broom) | |
mtcars %>% | |
crossv_kfold(k = 10) %>% | |
mutate(model = map(train, ~ lm(mpg ~ wt, .)), | |
result = map2(model, test, ~ augment(.x, newdata = .y))) %>% | |
unnest(result) |
This file contains 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
theme_blank <- function(...) { | |
ret <- theme_bw(...) | |
ret$line <- element_blank() | |
ret$rect <- element_blank() | |
ret$strip.text <- element_blank() | |
ret$axis.text <- element_blank() | |
ret$plot.title <- element_blank() | |
ret$axis.title <- element_blank() | |
ret$plot.margin <- structure(c(0, 0, -1, -1), unit = "lines", valid.unit = 3L, class = "unit") | |
ret |
This file contains 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(broom) | |
library(scales) | |
theme_set(theme_light()) | |
US <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv") %>% | |
mutate(new_deaths = deaths - lag(deaths)) %>% | |
filter(date >= "2020-02-26") | |
today <- max(US$date) |
This file contains 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(broom) | |
US <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv") %>% | |
mutate(new_deaths = deaths - lag(deaths)) %>% | |
filter(date >= "2020-02-26") | |
models <- tibble(degrees = 2:4) %>% | |
mutate(model = map(degrees, ~ lm(log(new_deaths + 1) ~ poly(date, .), data = US))) |
We can't make this file beautiful and searchable because it's too large.
This file contains 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
year,tag,number,year_total | |
2008,.htaccess,54,58390 | |
2008,.net,5910,58390 | |
2008,.net-2.0,289,58390 | |
2008,.net-3.5,319,58390 | |
2008,.net-4.0,6,58390 | |
2008,.net-assembly,3,58390 | |
2008,.net-core,1,58390 | |
2008,2d,42,58390 | |
2008,32-bit,19,58390 |
NewerOlder