Skip to content

Instantly share code, notes, and snippets.

View AndrewLJackson's full-sized avatar

Andrew Jackson AndrewLJackson

View GitHub Profile
@AndrewLJackson
AndrewLJackson / zero-to-one-fun
Created May 5, 2015 18:56
Useful functions between 0 and 1
rm(list=ls())
graphics.off()
# --------------------------------------------------------------------
# The Exponential decay function
# http://en.wikipedia.org/wiki/Exponential_function
# a sequence of x-values from 0 to 1000
x <- seq(0, 100, length=100)
@AndrewLJackson
AndrewLJackson / apply with multiple input functions
Created March 4, 2015 21:01
An example of how to use mapply() to evaluate a function requiring more than one input over a matrix or array.
X <- cbind(1:5, 6:10)
G <- 1:5
my.fun <- function(x,y){return(x+y)}
# ----------------------------------
@AndrewLJackson
AndrewLJackson / passing.arg.list.to.fun.R
Last active August 29, 2015 14:11
passing a set of arguments in a list into a function
a <- list(x=rnorm(10), y=rnorm(10), xlab = "x", ylab = "y", col = "blue", pch = 19, bty = "L", cex =2)
do.call('plot', a)
@AndrewLJackson
AndrewLJackson / z_score_covariance_matrices
Created December 9, 2014 10:58
Example code showing how transformations to the raw data affect estimation of covariance matrices, and hence ellipse size and shape.
rm(list=ls())
graphics.off()
library(mnormt)
set.seed(1)
# start of notes on re-scaling
#if x and y are two correlated variables with covariance matrix S then
#let x.z and y.z be their independently z-score transformed values.
@AndrewLJackson
AndrewLJackson / parse_month_year.R
Created December 3, 2014 12:43
How to convert month-year data to POSIX date format
# some data specifying the month and year
month <- c( "Sep-10",
"Oct-10",
"Nov-10",
"Jan-11")
# It would appear that strptime and related
# as.POSIXct functions require there to be a
# day specified. Here I prepend the month-year
@AndrewLJackson
AndrewLJackson / manual.recode.R
Created December 2, 2014 11:59
Manually recode variables using a series of == statements
# example code to reclassify existing coded data
# some data
mydata <- data.frame(orig.codes = c(1,1,1,2,2,3,4,4,5,6,7,7,7,8,8,9,10,10,10))
# a blank vector of NAs into which we will place the new codes
mydata$new.codes <- NA * numeric(length(mydata$orig.codes))
@AndrewLJackson
AndrewLJackson / helloworld.R
Created November 25, 2014 20:00
test gist
print('hello world')