Skip to content

Instantly share code, notes, and snippets.

@han-tun
han-tun / nflscrapr.md
Created January 15, 2020 22:25 — forked from guga31bb/nflscrapr.md
Simple guide for using nflscrapR

Basic nflscrapR tutorial

I get a lot of questions about how to get nflscrapR up and running. This guide is intended to help new users build interesting tables or charts from the ground up, taking the raw nflscrapR data.

Quick word if you're new to programming: all of this is happening in R. Obviously, you need to install R on your computer to do any of this. Make sure you save what you're doing in a script (in R, File --> New script) so you can save your work and run multiple lines of code at once. To run code from a script, highlight what you want, right click, and select Run line. As you go through your R journey, you might get stuck and have to google a bunch of things, but that's totally okay and normal. That's how I wrote this thing!

A huge thank you to Josh Hornsby (@Josh_ADHD) and Zach Feldman (@ZachFeldman3) for sharing code snippets for me to work with, and of course to the nflscrapR team ([Maksim Horowitz](https://twit

@han-tun
han-tun / Install
Created January 28, 2020 16:41 — forked from ines/Install
Streamlit + spaCy
pip install streamlit
pip install spacy
python -m spacy download en_core_web_sm
python -m spacy download en_core_web_md
python -m spacy download de_core_news_sm
library(tidyverse)
library(gganimate)
logistic_map <- function(r, steps = 500, init = .5) {
x <- vector('numeric', steps)
x[1] <- init
for (n in 2:steps) x[n] <- r * x[n-1] * (1 - x[n-1])
return(unique(round(tail(x, -100), 4)))
}
library(tidyverse)
# The actual dataset has ~3000 columns and 100ish rows per column
# Each column refers to a country and a state within that country
# There is also an "average" for the country column
# What is the best approach to grabbing ONLY the average column
bad_df <- tibble::tribble(
~category, ~usa_1, ~usa_2, ~usa_3, ~canada_1, ~canada_2, ~canada_13,
NA, "Alabama", "Texas", "Country Average", "Ontario", "Manitoba", "Country Average",
@han-tun
han-tun / walk_source.R
Created February 21, 2020 17:40 — forked from gadenbuie/walk_source.R
Walk an R source file and run each command in RStudio automatically on a delay
walk_source <- function(
file = NULL,
delay = 1.5,
clear_each_cmd = TRUE,
style = styler::tidyverse_style
) {
options("walk_source_cancel" = FALSE)
if (is.null(file)) {
txt <- rstudioapi::getSourceEditorContext()$contents
} else {
@han-tun
han-tun / proc_lifetest_survival_plot.sas
Created February 28, 2020 18:47 — forked from statgeek/proc_lifetest_survival_plot.sas
Customize a SAS Survival Graph to display Months
/*SAS PROC LIFETEST Survival Plot Template
Modifed by: F. Khurshed
Date: July 27, 2011
Description: I modified the basic GTL plot to
1) Changed the thickness of the lines plotted
2) Changed the X axis markers to 12 month intervals
3) Changed the Y axis markers to 0.25 level increments
4) Changed the label of the legend to be a macro variable called legend_label. This needs to be specified prior to output
@han-tun
han-tun / proc_lifetest_survival_plot.sas
Created February 28, 2020 18:47 — forked from statgeek/proc_lifetest_survival_plot.sas
Customize a SAS Survival Graph to display Months
/*SAS PROC LIFETEST Survival Plot Template
Modifed by: F. Khurshed
Date: July 27, 2011
Description: I modified the basic GTL plot to
1) Changed the thickness of the lines plotted
2) Changed the X axis markers to 12 month intervals
3) Changed the Y axis markers to 0.25 level increments
4) Changed the label of the legend to be a macro variable called legend_label. This needs to be specified prior to output
library(cartography)
library(sf)
mtq <- st_read(system.file("gpkg/mtq.gpkg",
package="cartography"))
bks <- getBreaks(v = mtq$MED, nclass = 5,
method = "quantile")
cols <- carto.pal(pal1 = "turquoise.pal", n1 = 5)
choroLayer(x = mtq, var = "MED",
breaks = bks, col = cols,
# Code for quick exploration of
# https://github.com/rfordatascience/tidytuesday/tree/master/data/2020/2020-05-26
# Video at https://youtu.be/kHFmtKCI_F4
library(tidyverse)
cocktails <- readr::read_csv("boston_cocktails.csv")
# Are name and row_id equivalent? -----------------------------------------
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r message=FALSE, warning=FALSE}
library(tidyverse)