Skip to content

Instantly share code, notes, and snippets.

@shuckle16
shuckle16 / tn-city-wiki.R
Created March 3, 2022 13:16
wikipedia scraper for population of TN cities
library(dplyr)
library(foreach)
library(ggplot2)
library(ggrepel)
library(glue)
library(janitor)
library(rvest)
library(doParallel)
registerDoParallel(3)
@shuckle16
shuckle16 / date-parse.R
Last active October 9, 2021 15:36
fast date parsing r
library(data.table)
library(tictoc)
library(lubridate)
dt <- data.table(
dayte = format(sample(Sys.Date() + 1:100, size = 1e6, replace = T), format = "%d%b%Y"),
a = sample(1000, size = 1e6, replace = T)
)
tic()
@shuckle16
shuckle16 / glmnet-sim
Created April 11, 2021 00:17
glmnet simulation -- compare using pca on predictors vs not
library(doMC)
library(glmnet)
library(tictoc)
library(tidyr)
library(ggplot2)
library(PCAtools)
y <- rgamma(10000, shape = 2, scale = 2000)
x <- y - matrix(rnorm(10000000, mean = 3000, sd = 100000), nrow = 10000)
@shuckle16
shuckle16 / florida-county-covid.R
Created May 22, 2020 21:13
plots county deaths / cases with moving averages
library(readr)
library(dplyr)
library(tidyquant)
library(ggplot2)
counties <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv")
counties %>%
filter(state == "Florida", county != "Unknown") %>%
group_by(county) %>%
@shuckle16
shuckle16 / usa-covid-19.R
Created April 23, 2020 18:43
scrapes covidtracking.com and plots tests, cases, and deaths over time
library(dplyr)
library(ggplot2)
library(tidyr)
library(stringr)
library(rvest)
usa_html <- read_html("https://covidtracking.com/data/us-daily")
usa_dat <- usa_html %>% html_table() %>% `[[`(1)
@shuckle16
shuckle16 / florida-covid-19
Last active August 23, 2020 22:37
# scrapes and plots some key covid metrics for florida
library(dplyr)
library(rvest)
library(stringr)
library(ggplot2)
library(tidyr)
STATE_OF_INTEREST <- "Florida"
STATE_OF_INTEREST <- str_to_lower(STATE_OF_INTEREST)
@shuckle16
shuckle16 / tourism-south-korea.R
Created January 3, 2020 14:17
scrapes wikipedia tourism table, makes chart
library(tidyverse)
library(rvest)
library(magrittr)
kor_tour <-
read_html("https://en.wikipedia.org/wiki/Tourism_in_South_Korea") %>%
html_nodes('table') %>%
extract2(4) %>%
html_table()