This file contains hidden or 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
#install.packages(ggplot2) | |
require(ggplot2) | |
set.seed(1410) # Make the sample reproducible | |
dsmall <- diamonds[sample(nrow(diamonds), 100), ] | |
head(dsmall) | |
?diamonds | |
qplot(carat, price, data = diamonds) | |
qplot(log(carat), log(price), data = diamonds) |
This file contains hidden or 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
# reading data into R: http://goo.gl/bAUmj | |
#install.packages("ISwR") | |
library("ISwR") | |
#factors | |
pain <- c(0,3,2,2,1) | |
fpain <- factor(pain,levels=0:3) | |
levels(fpain) <- c("none","mild","medium","severe") |
This file contains hidden or 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
require.install <- function(pkg, github=""){ | |
req <- suppressWarnings( | |
suppressMessages( | |
require(package=paste(pkg), character.only=TRUE) | |
) | |
); | |
#print(github); | |
if(!req){ | |
installOk <- FALSE; | |
if(length(github)<=0){ |
This file contains hidden or 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
KnitPost <- function(input, base.url = "/") { | |
require(knitr) | |
opts_knit$set(base.url = base.url) | |
fig.path <- paste0("figs/", sub(".Rmd$", "", basename(input)), "/") | |
opts_chunk$set(fig.path = fig.path) | |
opts_chunk$set(fig.cap = "center") | |
render_jekyll() | |
knit(input, envir = parent.frame()) | |
} |
This file contains hidden or 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
# Hadley's vocabulary with additional definitions and reproducible examples | |
This document takes the original [Vocabulary chapter](https://github.com/hadley/devtools/wiki/Vocabulary) from Hadley Wickham's in progress book "[Advanced R development: making reusable code](https://github.com/hadley/devtools/wiki)" and adds definitions and reproducible examples using [knitr](http://yihui.name/knitr/). Unless otherwise noted, the examples come straight from the help for each function or are modified versions from those examples. | |
```{r} | |
library("knitr") | |
``` | |
This file contains hidden or 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
# regression models from dalgaard | |
library("ISwR") | |
?thuesen | |
thuesen | |
attach(thuesen) | |
lm(short.velocity~blood.glucose) | |
summary(lm(short.velocity~blood.glucose)) #the median should not be far from zero, and the minimum and maximum should be roughly equal in absolute value | |
plot(blood.glucose,short.velocity) | |
abline(lm(short.velocity~blood.glucose)) |
This file contains hidden or 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
# This is a collection of scripts from Hadley Wickham's chapter on functions at https://github.com/hadley/devtools/wiki/Functions | |
# Components of a function | |
f <- function(x) x | |
f | |
formals(f) # argument list | |
body(f) # code inside the function | |
environment(f) # how variables are found |
This file contains hidden or 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
set.seed(123) | |
dependent <- rnorm(100) | |
set.seed(1234) | |
independent <- dependent*(rnorm(100)) | |
identity <- rep(1, 100) | |
identity | |
independent2 <- cbind (identity, independent2) | |
independent2 |
This file contains hidden or 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
brew install mysql | |
show databases; | |
exit; | |
mysql -u root -p | |
UPDATE mysql.user SET Password = PASSWORD('foo.bar') WHERE User = 'root'; | |
FLUSH PRIVILEGES; |
This file contains hidden or 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(ggplot2) | |
max_iter=25 | |
cl=colours() | |
step=seq(-2,0.8,by=0.005) | |
points=array(0,dim=c(length(step)^2,3)) | |
t=0 | |
for(a in step) | |
{ |