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
# solarized light color scheme for my TexShop setup | |
defaults write TeXShop background_R 0.99 | |
defaults write TeXShop background_G 0.96 | |
defaults write TeXShop background_B 0.89 | |
defaults write TeXShop commandred 0.0 | |
defaults write TeXShop commandgreen 0.0 | |
defaults write TeXShop commandblue 1.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
# check if you need to install these packages | |
pkg <- c("RODBC", "ggplot2") | |
inst <- pkg %in% installed.packages() | |
# inst | |
if (length(pkg[!inst]) > 0) { | |
install.packages(pkg[!inst]) | |
} | |
# load all required packages into session | |
lapply(pkg, library, character.only = TRUE) |
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
# http://trinkerrstuff.wordpress.com/2014/05/12/handling-s3methods-death-in-roxygen-4-0-0/ | |
pth <- "C:/Users/trinker/qdap/R" | |
fls <- file.path(pth, dir(pth)) | |
FUN <- function(x) { | |
cont <- readLines(x) | |
cont[grepl("#' @S3", cont)] <- "#' @export" | |
cont[length(cont) + 1] <- "" |
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
## 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 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
# 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 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
# 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 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
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 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(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 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(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 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(sqldf) | |
sqldf("SELECT | |
day | |
, avg(temp) as avg_temp | |
FROM beaver2 | |
GROUP BY | |
day;") | |
# day avg_temp |
NewerOlder