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
# source: http://bigdata-analyst.com/best-way-to-add-a-footnote-to-a-plot-created-with-ggplot2.html | |
library(gridExtra) | |
g <- arrangeGrob(p, sub = textGrob("Footnote", x = 0, hjust = -0.1, vjust=0.1, gp = gpar(fontface = "italic", fontsize = 18))) |
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
myfun <- function(){ | |
out <- list() | |
out$x <- LETTERS | |
out$y <- "hello world" | |
class(out) <- "vtable" | |
out | |
} | |
print.vtable <- function(x){ | |
cat("object of class vtable") | |
print(str(x$x)) |
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
address<- 'ftp://user:pw@sftp2.server.com' | |
items <- strsplit(getURL(address, .opts=curlOptions(ftplistonly=TRUE)), "\n")[[1]] | |
filename <- items[3] | |
bin = getBinaryURL(paste0(address, "/",filename)) | |
writeBin(bin, filename) |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
with open(fname,'r') as fin: | |
A = fin.readlines() |
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
as.Date(string, "%Y") | |
# for a list of options, see table in | |
# http://blog.mollietaylor.com/2013/08/date-formats-in-r.html |
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
input <- c("kitten", "dog") | |
candidates <- c("sitting", "sittingAround", "doggy") | |
get_best_match <- function(input, candidates, repeatInput = FALSE){ | |
distM <- adist(as.character(input), as.character(candidates)) | |
if (repeatInput){ | |
out <- data.frame(input, | |
bestMatch = candidates[apply(distM, 1, which.min)], | |
distance = apply(distM, 1, min)) | |
} else{ |
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
%qtconsole |
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
interactiveScatter <- function(xvar, yvar, data, | |
tooltip = c(xvar, yvar), title = "", | |
lmline = TRUE){ | |
require(rCharts) | |
x <- xvar | |
y <- yvar | |
tooltipString <- paste0("#!function(item){return ", |
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
# code copied from: | |
# http://heuristically.wordpress.com/2009/12/23/compare-performance-machine-learning-classifiers-r/ | |
# load the ROCR package which draws the ROC curves | |
require(ROCR) | |
# create an ROCR prediction object from rpart() probabilities | |
x.rp.prob.rocr <- prediction(x.rp.prob[,2], BreastCancer[ind == 2,'Class']) | |
# prepare an ROCR performance object for ROC curve (tpr=true positive rate, fpr=false positive rate) | |
x.rp.perf <- performance(x.rp.prob.rocr, "tpr","fpr") |
OlderNewer