Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Strayer nstrayer

View GitHub Profile
@nstrayer
nstrayer / fun_w_rapply.R
Last active Mar 12, 2021
Experiments with the function rapply in R's base library
View fun_w_rapply.R
library(magrittr)
str_replace_all <- function(text, pattern, replacement){
gsub(pattern = pattern, replacement = replacement, x = text, perl = TRUE)
}
str_remove_all <- function(text, pattern){
str_replace_all(text, pattern = pattern, replacement = "")
}
@nstrayer
nstrayer / self_rendering_md.css
Created Feb 4, 2020
CSS to make HTML build from basic markdown look like generating markdown but with the style preserved
View self_rendering_md.css
@import url('https://fonts.googleapis.com/css?family=Inconsolata&display=swap');
body {
--text-color: #2b2a2a;
--link-color: #005fb1;
font-family: 'Inconsolata', monospace;
font-size: 15px;
color: var(--text-color);
}
@nstrayer
nstrayer / simulate_mnar_data.R
Created Jan 21, 2020
R Script to simulate missing not at random data and look at performance of different imputation strategies.
View simulate_mnar_data.R
library(tidyverse)
n <- 150
sensitivity_threshold <- 5
data <- tibble(
a = rgamma(n = n, shape = 5, rate = 0.5),
b = rgamma(n = n, shape = a/2, rate = 0.5)
)
generate_missing_data <- function(i){
@nstrayer
nstrayer / no_good_very_bad_data.csv
Created Aug 8, 2018
simple csv of some hard-to-histogram data.
View no_good_very_bad_data.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
x
0.8749728356504094
0.9658539380522311
1.0988786266989092
0.9270070375557564
1.1795131996034487
1.0716089699247264
0.8728550463211999
1.0682964292826937
0.9766832723965019
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>(function() {
// If window.HTMLWidgets is already defined, then use it; otherwise create a
// new object. This allows preceding code to set options that affect the
// initialization process (though none currently exist).
window.HTMLWidgets = window.HTMLWidgets || {};
View spell_data.csv
We can't make this file beautiful and searchable because it's too large.
time,direction,accel,label,recording_id,caster
0.057,m_x,-0.1,Alohomora,1_aiknf,Nick
0.102,m_x,-0.15,Alohomora,1_aiknf,Nick
0.154,m_x,-0.36,Alohomora,1_aiknf,Nick
0.205,m_x,-0.52,Alohomora,1_aiknf,Nick
0.254,m_x,-0.92,Alohomora,1_aiknf,Nick
0.307,m_x,-1.32,Alohomora,1_aiknf,Nick
0.356,m_x,-1.23,Alohomora,1_aiknf,Nick
0.407,m_x,-1.02,Alohomora,1_aiknf,Nick
View simpleD3Scatter.R
library(tidyverse)
library(htmltools)
# devtools::install_github('ramnathv/htmlwidgets')
library(htmlwidgets)
# devtools::install_github('timelyportfolio/d3r')
library(d3r)
data <- data_frame(x = rnorm(50), y = rnorm(50));
browsable(
View general_data.JSON
{"edges":[{"from":1,"to":5550},{"from":1,"to":5551},{"from":2,"to":5559},{"from":2,"to":5560},{"from":2,"to":5561},{"from":3,"to":5550},{"from":3,"to":5551},{"from":3,"to":5559},{"from":3,"to":5560},{"from":4,"to":5550},{"from":4,"to":5551},{"from":4,"to":5552},{"from":4,"to":5553},{"from":4,"to":5555},{"from":4,"to":5556},{"from":4,"to":5561},{"from":5,"to":5550},{"from":5,"to":5551},{"from":6,"to":5550},{"from":6,"to":5551},{"from":7,"to":5550},{"from":7,"to":5551},{"from":8,"to":5558},{"from":9,"to":5550},{"from":9,"to":5551},{"from":9,"to":5561},{"from":10,"to":5550},{"from":10,"to":5551},{"from":10,"to":5552},{"from":10,"to":5554},{"from":10,"to":5555},{"from":10,"to":5556},{"from":10,"to":5559},{"from":11,"to":5550},{"from":11,"to":5551},{"from":11,"to":5561},{"from":12,"to":5550},{"from":12,"to":5551},{"from":13,"to":5550},{"from":13,"to":5551},{"from":14,"to":5550},{"from":14,"to":5551},{"from":14,"to":5561},{"from":15,"to":5550},{"from":15,"to":5551},{"from":16,"to":5557},{"from":16,"to":5561},{"from
View file199f5b2f550a.R
library(tidyverse)
get_boot_int <- function(n){
data <- data_frame(
outcome = rnorm(n, 60, 20),
treat = sample(c(0,1), n, replace = T)
) %>%
mutate(outcome = ifelse(treat == 1, outcome + 5, outcome))
data %>%
group_by(treat) %>%
View file199f5eb98261.R
---
title: "Homework6"
author: "Ben Lane"
date: "11/22/2017"
output: pdf_document
---
### Grade 44/50