Skip to content

Instantly share code, notes, and snippets.

Jeromy Anglim jeromyanglim

Block or report user

Report or block jeromyanglim

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View openxlsx_write_data_frame.r
# Function to write data.frame to xlsx spreadsheet
write_xlsx <- function(data, file, sheetname = "Sheet1", rowNames = TRUE, ...) {
wb <- createWorkbook()
addWorksheet(wb, sheetname)
writeData(wb, sheetname, data, rowNames = rowNames, ...)
saveWorkbook(wb, file = file, overwrite = TRUE)
# Example
jeromyanglim / makefile
Created Nov 4, 2017
example of a makefile that runs an r job and sends an email when done.
View makefile
mode=standard # e.g., quick, standard, publication
make models mode=$(mode)
make ppc mode=$(mode)
make standard-figures mode=$(mode)
make yhat mode=$(mode)
View google-scholar-bookmarklet
javascript:location %3D %27
jeromyanglim / import_qualtrics_csv
Last active Feb 23, 2017
Function that assists with importing CSV data from Qualtrics into R; it also allows for choosing which categorical variables should be numeric and which labelled.
View import_qualtrics_csv
import_csv_qualtrics <- function(file) {
# import a csv file exported from Qualtrics
# Qualtrics places variable labels in the second row.
# This function removes that second row and returns the data frame.
# taken from:
DF <- read.csv(file, skip=2, header=FALSE)
DF2 <- read.csv(file)
names(DF) <- names(DF2)
jeromyanglim / covlm.r
Last active Jul 25, 2016
Function that allows you to run a linear model on a covariance matrix using lavaan
View covlm.r
# see
covlm <- function(dv, ivs, n, cov) {
# Assumes lavaan package
# library(lavaan)
# dv: charcter vector of length 1 with name of outcome variable
# ivs: character vector of names of predictors
# n: numeric vector of length 1: sample size
# cov: covariance matrix where row and column names
jeromyanglim / freqtable.r
Last active Jul 20, 2016
Provide frequencies and proportions typically for a data frame containing multiple varies using the same numeric response format (e.g., 1 to 5 likert)
View freqtable.r
freqtable <- function(X) {
# X: data.frame of typically survey items
# Code assumes that all items are numeric (i.e., 1 to 5, rather than text labels)
unique_values <- unique(unlist(sapply(X, unique)))
su <- sort(unique_values)
freq <- t(sapply(X, function(Z) table(factor(Z, su))))
prop <- t(sapply(X, function(Z) prop.table(table(factor(Z, su)))))
list(freq = freq, prop = prop)
jeromyanglim / charnum2num.r
Last active Aug 29, 2015
Take a data.frame x and convert all columns of class character that appear to be numeric into numeric
View charnum2num.r
charnum2num <- function(x) {
# Purpose
# Take a data.frame x and convert all columns of class character that appear to be numeric into numeric
# x is a data.frame
# code taken from library(Hmisc) and included here to avoid the dependency <- function (x, what = c("test", "vector"), extras = c(".", "NA"))
what <- match.arg(what)
old <- options(warn = -1)
jeromyanglim / CollapseHeadings.bas
Created Dec 14, 2012
Simple VBA script that I use in Mac Word for collapsing Up headings in Outline View; it works for me, but I've had it floating around for so long, I barely remember how it works.
View CollapseHeadings.bas
Sub CollapseHeadings()
' Use this code at your own risk
' It works for me. I use it in Word documents while in Outline View
' for documents set up with Outline View in mind
' Remember Ctrl + Pause Break will get break the program
On Error GoTo ErrorHandler
Dim r As Range, o As Integer, p As Long, f As Boolean
Dim currentOutlineLevel, nextOutlineLevel
Dim timeout As Integer ' used to pre
View keys.css
border-color:#ccc #aaa #888 #bbb;
padding:2px 6px;
-moz-box-shadow:0 2px 0 rgba(0, 0, 0, 0.2),0 0 0 1px #ffffff inset;
View rstudio-markdown-error.rmd
* asdf
You can’t perform that action at this time.