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
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
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
// 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
address<- 'ftp://user:[email protected]' | |
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
# notes: it's all about fine-tuning the details: | |
# good color palette (-> google 'color palette') | |
# white borders and font | |
# gray edges (even better when weighted) | |
# | |
library(qgraph) | |
adj=matrix(sample(0:1,10^2,TRUE,prob=c(0.8,0.2)),nrow=10,ncol=10) | |
groups <- list(group1 = 1:4, | |
group2 = 5:7, | |
group3 = 8:10) |
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
# 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
cut_equal <- function(x, n = 3){ | |
q <- quantile(x, prob= seq(0,1,length.out = n+1 )) | |
cut(x, | |
breaks = as.numeric(q), | |
include.lowest=TRUE, labels = 1:n) | |
} |
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
# getting process id so we can kill it | |
pid <- system( "Rscript sample.R 500 > test2.txt & | |
echo $!", intern = TRUE) | |
system(paste(sprintf("kill %s", pid))) |