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
# Correlation ellipses | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("ellipse") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Function to plot colored correlation ellipses | |
correlationEllipses <- function(cor){ | |
require(ellipse) |
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
# Illustrative use of plyr | |
# LOAD LIBRARIES REQUIRED | |
library(plyr); | |
library(XML) | |
# FIGURE OUT PATTERN OF URL FOR EACH SEASON | |
url.b1 = 'http://ca.sports.yahoo.com/nhl/stats/byposition?pos=C,RW,LW,D'; |
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
# run length encoding, or counting streaks | |
rle | |
# combinations, combinatorics, n choose k | |
combn | |
# allows you to dump an object in the form of R code | |
dput | |
# modulo |
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
require(ggplot2) | |
### Boot ### | |
DimensionTester <- function(object, niterations = 50, dimstotest = 0){ | |
if(length(dimstotest) == 1){dimstotest <- 1:(ncol(object)*2)} | |
Parameters <- expand.grid(1:niterations, dimstotest) | |
DoPCA <- function(dims){ |
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
Jaccard <- function(matrix){ | |
Intersection <- matrix %*% t(matrix) | |
Union <- ncol(matrix) - (!matrix) %*% t(!matrix) | |
Jaccard <- Intersection / Union | |
return(Jaccard) | |
} |
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
require(ggplot2) | |
### Boot ### | |
DimensionTester <- function(object, niterations = 50, dimstotest = 0){ | |
if(length(dimstotest) == 1){dimstotest <- 1:(ncol(object)*2)} | |
Parameters <- expand.grid(1:niterations, dimstotest) | |
DoPCA <- function(dims){ |
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
Gister <- function(rawurl){ | |
require(RCurl) | |
write.table(unlist(strsplit(getURL(rawurl, ssl.verifypeer = FALSE), "\n")), | |
"GistCode.txt", row.names = F, quote = F) | |
source("GistCode.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
require(snow) | |
VariabletoExport <- 5 | |
TheFunction <- function(x){ | |
TimeWaster <- mean(rnorm(100000, 0, 1)) | |
x^2 + TimeWaster + VariabletoExport | |
} | |
FunctionInput <- 1:1000 |
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
#@author Michael J Bommarito | |
#@contact michael.bommarito@gmail.com | |
#@date Feb 20, 2011 | |
#@ip Simplified BSD, (C) 2011. | |
# This is a simple example of an R script that will retrieve | |
# public tweets from a given hashtag. | |
library(RJSONIO) | |
# This function loads stored tag data to determine the current max_id. |
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
total <- 100 | |
# create progress bar | |
pb <- txtProgressBar(min = 0, max = total, style = 3) | |
TheFunction <- function(i){ | |
Sys.sleep(0.05) | |
setTxtProgressBar(pb, i) | |
} | |
lapply(1:total, TheFunction) |