Skip to content

Instantly share code, notes, and snippets.

@seankross
seankross / jazz.txt
Created May 18, 2018 18:20
Jazz Toni Morrison
From "Jazz" by Toni Morrison
It's nice when grown people whisper to each other under the covers. Their
ecstasy is more leaf-sigh than bray and the body is the vehicle, not the point.
They reach, grown people, for something beyond, way beyond and way, way down
underneath tissue. They are remembering while they whisper the carnival dolls
they won and the Baltimore boats they never sailed on. The pears they let hang
on the limb because if they plucked them, they would be gone from there and who
else would see that ripeness if they took it away for themselves? How could
anybody passing by see them and imagine for themselves what the flavor would
@seankross
seankross / sounds.r
Last active May 1, 2018 01:26 — forked from ncarchedi/sounds.r
# Script to help understanding of S3 object-oriented programming
# in R using classes and methods
# Constructor functions for various classes of animal
pig <- function() structure(list(), class=c("pig", "animal"))
dog <- function() structure(list(), class=c("dog", "animal"))
cat <- function() structure(list(), class=c("cat", "animal"))
makeSound <- function(x) UseMethod("makeSound")
@seankross
seankross / schools.R
Created March 29, 2018 19:08
Graph for Clare
# You can find pch values for shapes here:
# https://cdn-images-1.medium.com/max/1600/1*0QEVFHrgqmkVsCVCQceh6w.jpeg
data <- data.frame(
Name = c("Ohio State", "Purdue", "Indiana", "Wisconsin", "Nebreaska"),
Min = c(0.37, 0.25, 0.13, 0.22, 0.28),
Max = c(0.88, 0.57, 0.68, 0.77, 0.63),
Value = c(0.51, 0.32, 0.24, 0.65, 0.57),
Pch = c(1, 2, 5, 6, 22),
stringsAsFactors = FALSE
@seankross
seankross / emilyp.R
Created March 7, 2018 04:04
Getting p-values out of a model, two ways
berkeley <- as.data.frame(UCBAdmissions)
model <- glm(Admit ~ Gender + Dept + Freq, data = berkeley, family = "binomial")
# Base R
model_summary <- summary(model)
model_summary$coefficients[,4]
# Or become one of the cool kids
library(shiny)
library(miniUI)
ui <- miniPage(
gadgetTitleBar("My Gadget"),
miniContentPanel(
## Your UI items go here.
)
)
library(dplyr)
c(2, 5, 6) %>% sum()
cars_i_want <- mtcars %>%
filter(mpg > 20) %>%
filter(cyl == 4) %>%
arrange(hp)
mtcars %>%
@seankross
seankross / expected.R
Created September 22, 2017 20:33
For Stephan
steph <- structure(c(148L, 65L, 198L, 53L, 16L, 2004L), .Dim = c(3L, 2L
), .Dimnames = structure(list(c("EatNoTrans", "Request", "Stealing"
), c("0", "1")), .Names = c("", "")), class = "table")
chisq_steph <- chisq.test(steph)
chisq_steph$expected
library(dplyr)
library(purrr)
set.seed(2017-06-27)
# Imagine this function gives us measurements from nature
data_generator <- function(n = 500){
data_frame(var1 = rnorm(500)) %>%
mutate(var2 = var1 + rnorm(500)) %>%
mutate(var3 = var1 * var2 + rnorm(500)) %>%
library(aws.polly)
jeff <- synthesize("Hello, I am Jeff Leek. Take a look at this chart on my left.", "Joey")
plot(jeff@left, type = "l")
library(dplyr)
x <- mtcars %>%
group_by(cyl) %>%
sample_frac(replace = TRUE)
mtcars %>%
group_by(cyl) %>%
summarise(sum = n())