Skip to content

Instantly share code, notes, and snippets.

@statzhero
statzhero / csv-ssl
Created February 7, 2014 14:50
An R function for downloading CSV-files over SSL
read.url <- function(url, ...){
temporaryFile <- tempfile()
download.file(url, destfile = temporaryFile, method = "curl")
url.data <- read.csv(temporaryFile, ...)
return(url.data)
}
@statzhero
statzhero / mbox-regex
Created August 20, 2013 14:12
A regular expression that finds email addresses saved in a Apple Mail mbox file. \+ is omitted.
grep -Eiorh '[a-zA-Z]{1}[a-zA-Z0-9_\.\-]{1,26}@[a-zA-Z0-9_\.\-]+\.(?:[a-zA-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$' mbox | sort | uniq > emails.txt
@statzhero
statzhero / gist:8217552
Created January 2, 2014 10:48
R gist for creating a few random IQ scores (credit R. Burns)
iqcor <- matrix(.5, nrow=2, ncol=2)
diag(iqcor) <- 1
iqcor
require(MASS)
mvrnorm(10, mu=c(100, 100), Sigma=100*iqcor)
@statzhero
statzhero / server.R
Created January 15, 2014 12:15 — forked from pssguy/server.R
# libraries used. install as necessary
library(shiny)
library(RJSONIO) # acquiring and parsing data
library(ggplot2) # graphs
library(plyr) # manipulating data
library(lubridate) #dates
library(stringr)
trim.leading <- function (x) sub("^\\s+", "", x)
no_missing <- function(x) sum(is.na(x))
@statzhero
statzhero / row-sample
Last active July 13, 2017 04:45
A function to make analysing a random subset easier.
row.sample <- function(dta, rep = 20) {
dta <- as.data.frame(dta) # for single variables
dta[sample(1:nrow(dta), rep, replace=FALSE), ]
}
table()
prop.table(mytable) # cell percentages
sort(table(x), decreasing = TRUE)
# Show missing data in table as default
table = function (..., useNA = 'ifany') base::table(..., useNA = useNA)
@statzhero
statzhero / list_named_ranges.vba
Created December 11, 2018 20:53
Excel VBA list named ranges in sheet
Sub Test_NamedRanges()
For Each nm In ThisWorkbook.Names
If nm.RefersToRange.Parent.Name = Sheet10.Name Then MsgBox nm.Name
Next nm
End Sub
# Simple charts
library(magrittr)
d <- rnorm(1000, 1, 1)
density(d) %>% plot
d2 <- rlnorm(1000, 1, 1)
density(d2) %>% plot
loc <- function(x) { log(m^2 / sqrt(s^2 + m^2)) }
shape <- function(x) { sqrt(log(1 + (s^2 / m^2))) }