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
#+ spinme-chunk, eval = FALSE, echo = FALSE | |
.scriptName <- basename(sys.frame(1)$ofile) | |
.spinOutput <- knitr::spin(.scriptName, knit = TRUE) | |
stop(sprintf("Ignore this error - your output is ready at:\n%s", | |
normalizePath(.spinOutput)), | |
call. = FALSE) | |
#+ spinme-done, eval = TRUE, echo = TRUE |
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
# There are two humans: `human` and `angry_human`. They only differ in the fact | |
# that angry humans have a frown on their face. | |
# Example code: | |
# dean <- human("Dean") | |
# ex <- angry_human("Ex") | |
# plot(dean) | |
# plot(ex) | |
# When plotting `dean`, RStudio shows me all the available parameters. |
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
# rasmusab/beepr package is great for telling you when your R code finishes running. | |
# But if the code throws an error, the beep will never come, and you won't know that | |
# it finished running until you visually check. | |
# Solution: change the error handler to a failure beep. | |
# Example | |
foo <- function(success = TRUE) { | |
if (!success) { | |
stop("Error!") | |
} |
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
# Suppose a function has an argument "x". If a "child function" has multiple | |
# argument beginning with "x" and I want to pass the param "x" to its parent, | |
# I get error: `argument n matches multiple formal arguments` | |
# The reason this happens is clear, but at 3am my brain is firing blanks | |
# trying to find a solution. Help! | |
library(magrittr) | |
foo <- function(x, ...) UseMethod("foo") | |
foo.parent <- function(x, n = 5, ...) n |
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
Type | Subtype | Country | Name | Alcohol_Content | Price | Sweetness | |
---|---|---|---|---|---|---|---|
WINE | TABLE WINE RED | CANADA | COPPER MOON - MALBEC | 14 | 30.99 | 0 | |
WINE | TABLE WINE WHITE | CANADA | DOMAINE D'OR - DRY | 11.5 | 32.99 | 0 | |
WINE | TABLE WINE RED | CANADA | SOMMET ROUGE | 12 | 29.99 | 0 | |
WINE | TABLE WINE WHITE | CANADA | MISSION RIDGE - PREMIUM DRY WHITE | 11 | 33.99 | 1 | |
WINE | TABLE WINE RED | UNITED STATES OF AMERICA | ZINFANDEL - BIG HOUSE CARDINAL ZIN | 13.5 | 36.99 | 0 | |
WINE | TABLE WINE RED | FRANCE | LE VILLAGEOIS RED - CELLIERS LA SALLE | 11 | 34.99 | 0 | |
WINE | TABLE WINE RED | CANADA | SAWMILL CREEK - MERLOT | 12.5 | 119 | 0 | |
WINE | TABLE WINE WHITE | CANADA | SOLA | 12 | 32.99 | 0 | |
WINE | TABLE WINE WHITE | CANADA | GANTON & LARSEN PROSPECT - PINOT BLANC BIRCH CANOE 2011 | 11.5 | 13.99 | 0 |
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
n <- 50 | |
a <- 2 | |
b <- -3 | |
sigSq <- 0.5 | |
x <- runif(n) | |
norm <- rnorm(n, sd = sqrt(sigSq)) | |
y <- a + b * x + norm | |
plot(x,y) | |
abline(a, b, col = "blue") |
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
n <- 50 | |
a <- 2 | |
b <- -3 | |
sigSq <- 0.5 | |
x <- runif(n) | |
norm <- rnorm(n, sd = sqrt(sigSq)) | |
y <- a + b * x + norm | |
plot(x,y) | |
abline(a, b, col = "blue") |
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
Dean Attali's View of the World | |
======================================================== | |
First, let's load the data and the required libraries (in this case, just lattice for plotting) | |
**Note:** The data is available [here](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt) | |
```{r} | |
library("lattice") | |
gDat <- read.delim("gapminderDataFiveYear.txt") | |
``` |
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
Dean Attali | |
================================= | |
**STAT 545A hw 3** | |
**Sept 22 2013** | |
Exercises done: | |
* Average GDP/cap in each continent when the data was first and last collected **(easy)** | |
* Trimmed mean statistics for life expectancy in each continent for every year **(fun)** | |
* Absolute and relative world population in each of the continents **(very fun)** | |
* A list of all countries that at some point had their population size decrease **(very fun)** |
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
Dean Attali | |
================================= | |
**STAT 545A hw 3** | |
**Sept 22 2013** | |
Exercises done: | |
* Average GDP/cap in each continent when the data was first and last collected **(easy)** | |
* Trimmed mean statistics for life expectancy in each continent for every year **(fun)** | |
* Absolute and relative world population in each of the continents **(very fun)** | |
* A list of all countries that at some point had their population size decrease **(very fun)** |
OlderNewer