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
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 |
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
# 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") |
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
# 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 |
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
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 |
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(shiny) | |
library(miniUI) | |
ui <- miniPage( | |
gadgetTitleBar("My Gadget"), | |
miniContentPanel( | |
## Your UI items go here. | |
) | |
) |
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(dplyr) | |
c(2, 5, 6) %>% sum() | |
cars_i_want <- mtcars %>% | |
filter(mpg > 20) %>% | |
filter(cyl == 4) %>% | |
arrange(hp) | |
mtcars %>% |
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
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 |
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(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)) %>% |
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(aws.polly) | |
jeff <- synthesize("Hello, I am Jeff Leek. Take a look at this chart on my left.", "Joey") | |
plot(jeff@left, type = "l") |
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(dplyr) | |
x <- mtcars %>% | |
group_by(cyl) %>% | |
sample_frac(replace = TRUE) | |
mtcars %>% | |
group_by(cyl) %>% | |
summarise(sum = n()) |