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
## Add an alpha value to a colour | |
add.alpha <- function(col, alpha=1){ | |
if(missing(col)) | |
stop("Please provide a vector of colours.") | |
apply(sapply(col, col2rgb)/255, 2, | |
function(x) | |
rgb(x[1], x[2], x[3], alpha=alpha)) | |
} |
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
# http://randyzwitch.com/automated-re-install-of-packages-for-r-3-0/ | |
# if using RStudio, make sure to unload all packages that are pre-loaded except for utils: | |
# we have to use the install.packages() function in utils for the re-installation | |
# Get currently installed packages | |
package_df <- as.data.frame(installed.packages("/Library/Frameworks/R.framework/Versions/2.15/Resources/library")) | |
package_list <- as.character(package_df$Package) | |
package_list # get a package list installed on R 2.15.X | |
length(package_list) |
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
# load required libraries | |
library(shiny) | |
library(plyr) | |
library(ggplot2) | |
library(googleVis) | |
library(reshape2) | |
####creation of example data on local directory for uploading#### |
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
Follow the steps at http://cufflinks.cbcb.umd.edu/tutorial.html | |
1. Download Cufflinks version 2.0.2 (BETA), Source code | |
2. tar -zxvf cufflinks-2.0.2.tar.gz (before final installation, make sure related tools are installed! See below) | |
Installing Boost C++ libraries | |
1. Download Boost at http://www.boost.org/users/download/ | |
2. The bjam boost engine is also required. If MacPort is installed, then use the command sudo port install boost. It will take care of everything. | |
3. If #2 won't work, try (preferred way!) | |
tar -xzf boost_1_50_0.tar.gz |
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(sqldf) | |
sqldf("SELECT | |
day | |
, avg(temp) as avg_temp | |
FROM beaver2 | |
GROUP BY | |
day;") | |
# day avg_temp |
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(randomForest) | |
# download Titanic Survivors data | |
data <- read.table("http://math.ucdenver.edu/RTutorial/titanic.txt", h=T, sep="\t") | |
# make survived into a yes/no | |
data$Survived <- as.factor(ifelse(data$Survived==1, "yes", "no")) | |
# split into a training and test set | |
idx <- runif(nrow(data)) <= .75 | |
data.train <- data[idx,] |
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(stringr) | |
names(iris) | |
#[1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" | |
names(iris) <- str_replace_all(names(iris), "[.]", "_") | |
names(iris) | |
#[1] "Sepal_Length" "Sepal_Width" "Petal_Length" "Petal_Width" "Species" | |
s <- c("Go to Heaven for the climate, Hell for the company.") | |
str_extract_all(s, "[H][a-z]+ ") |
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
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
const int MAX_ROWS = 3; | |
const int MAX_COLS = 4; | |
// 2-D array of integers | |
int MyInts[MAX_ROWS][MAX_COLS] = { {34, -1, 879, 22}, |
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
#spirographR() will produce either a hypotrochoid or an epitrochoid. | |
#'A' is a circle of radius 'A.RADIUS' | |
#'B' is a circle of radius 'B.RADIUS' travelling around 'A' | |
#'C' is a point relative to the center of 'B' which rotates with the turning of 'B'. | |
#'BC' is the distance from the center of 'B' to 'C' | |
#'A.REV' is the number of revolutions that 'B' should travel around 'A' | |
#'N.PER.A.REV' is the number of radial increments to be calculated per revolution | |
#'A.CEN' is the position of the center of 'A' | |
# |
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
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("ReadImages", "reshape", "ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Image URL: | |
allImageURLs <- c("http://media.charlesleifer.com/blog/photos/thumbnails/akira_940x700.jpg", | |
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg", | |
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Official_portrait_of_Barack_Obama.jpg/441px-Official_portrait_of_Barack_Obama.jpg", | |
"http://cache.boston.com/universal/site_graphics/blogs/bigpicture/obama_11_05/obama22_16604051.jpg", |
NewerOlder