Skip to content

Instantly share code, notes, and snippets.

@ZeccaLehn
ZeccaLehn / Find_Packages.md
Last active August 29, 2015 14:04
Finds unique packages within .Rmd files, from multiple subdirectories
# #Majority Vote Accuracy
# For Johns Hopkins / Machine Learning in R
# n <- 5 # Independent Classifiers
# k <- 3 #
#
# accuracy <- 0.7
#
# majorityAccu(5, 3, .7) # 83.7% Accuracy
# majorityAccu(101, 51, .7) #99.9% Accuracy
@ZeccaLehn
ZeccaLehn / CompressionComparisons.md
Last active August 29, 2015 14:12
Compression Comparisons in R -- Research

Code I presented in Johns Hopkins Data Science Capstone:

Size of compressed file as percentage of the original file

                   Adaptive 
                   Huffman Lempel-Ziv
     LaTeX file     66%      44%
     Speech file     65%     64%
     Image file      94%     88%

http://www.data-compression.com/lossless.html
@ZeccaLehn
ZeccaLehn / Search R Packages by Letter
Created December 29, 2014 17:04
Search R Packages by Letter
#Search installed packages by first letter -- regardless of upper/lower case (by 's' here)
grep("^[s]", attributes(installed.packages())$dimnames[[1]], value = TRUE, ignore.case = TRUE)
@ZeccaLehn
ZeccaLehn / BINOMIAL_PROBABILITIES
Last active August 29, 2015 14:13
BINOMIAL PROBABILITIES
# Quick GIST I wrote in the Data Science Capstone JHU forum (Dec 2014)
# It appears if the one of us draws 5 random tweets or news excerpts as the grading criteria calls for,
# the probability that none of the five match the top-word is 32.8%--assuming the
# true accuracy of model is 20%.
# Overall, if the top-word as criteria for success is used, where 4 reviewers using 5 random samples,
# the probability that none of the 20 predictions match the top word is only 1.2%.
@ZeccaLehn
ZeccaLehn / stringToChar.r
Last active August 29, 2015 14:13
String to Characters in R -- "Hello World" Function
stringToChar<- function( example ){
example <- as.character(example)
letters <- strsplit(example,"")[[1]]
for (i in letters[1:length(letters)] ) { print(i) }
}
@ZeccaLehn
ZeccaLehn / AutomagicDir.md
Last active August 29, 2015 14:15
Automagically Set R Working Directory on Linux Machine

Sets the working directory in R on a Linux system after and are replaced with actual folder names.

Alows for sharing code without each user having to change the HOME variable (e.g., "home/myMachine/Projects/First"

setwd(paste0(Sys.getenv("HOME"),"/<TopDir>/<Root>")) 

For Windows, use proper slash direction and notation.

@ZeccaLehn
ZeccaLehn / beeprExample.md
Created March 1, 2015 01:07
[R] Beeps when ready

Calls a sound -- useful when waiting...

install.packages("beepr")
library(beepr)
beep(sound = 3, expr = NULL) #Fanfare!!

1: "ping"

@ZeccaLehn
ZeccaLehn / MAImp.test.r
Last active August 29, 2015 14:19 — forked from timelyportfolio/MAImp.test.r
Portfolio Plots
# Loads current gist with function
# https://gist.github.com/timelyportfolio/1405187
# dev.off(); plot(1)
library(devtools)
source_gist("1405187")
require(quantmod)
require(PerformanceAnalytics)
@ZeccaLehn
ZeccaLehn / sinkPrint.R
Last active August 29, 2015 14:22
Sink and Print from a text file in R
sink("file.txt", append = T,
split = FALSE) # Direct text to "file.txt"
print("hello world")
print("hello world again")
shell.exec("file.txt") # Open text file in editor
unlink("file.txt") # Closes sink and now prints all to console
closeAllConnections()