Skip to content

Instantly share code, notes, and snippets.

@dewittpe
dewittpe / stirling.R
Last active December 29, 2015 14:39
Find the partitions labels for placing n distinct objects into k non-distinct boxes.
################################################################################
# file: stirling.R
# author: Peter DeWitt
# date: 27 Nov 2013
#
# purpose:
#
# 1) stirling2(n, k) returns the Stirling number of the second kind. This is
# the number of ways to place n descript objects into k non-nondescript boxes,
# non-empty boxes.
@dewittpe
dewittpe / exampleTableMultcol.Rhtml
Created June 11, 2014 05:07
Example of a table with two header rows and one spanning multiple columns
<!DOCTYPE html>
<html>
<head>
<title>Example of a table with two header rows and one spanning multiple columns</title>
</head>
<body>
<h1> Example of a table with two header rows - year spanning two columns (n and %). </h1>
Create a silly example table:
# My answer to http://stackoverflow.com/questions/25272387
library(ggplot2)
library(reshape2)
library(dplyr)
library(magrittr)
library(splines)
set.seed(42)
# Tweet from Erin Jonaitis:
# Hey nerds. y[x==1] is shorthand for "elements of y where the corresponding x
# is 1." What if I want y[i] such that x[i+e]==1?
set.seed(42)
# random data for example
y <- round(rnorm(30), 2)
x <- sample(1:3, size = 30, replace = TRUE)
@dewittpe
dewittpe / random-number-images.R
Created June 15, 2015 22:29
Random Number Generator Graphics
# ---------------------------------------------------------------------------- #
# file: random-number-images.R
# author: Peter DeWitt
#
# inspired by the work presented at http://boallen.com/random-numbers.html
# this file generates several images based on random number generators in R
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# libraries
# ---------------------------------------------------------------------------- #
@dewittpe
dewittpe / select_cols.R
Created September 13, 2015 03:48
Regular expressions for selecting columns to read into R via `readr::read_delim`
# Example using regular expressions and setting col_types for use with
# readr::read_delim
# function select_cols
# args:
# clnms a character vector of column names
# rexprs a character vector of regular expressions to search clnms for. These
# rexprs select the columns form the .csv
# types a character vector of "l", "i", "d", "c" for logical, integer,
# double, and character. see documentation for readr for more detail
@dewittpe
dewittpe / build-script.R
Last active November 28, 2021 15:47
Equation Numbering in Rmd
library(rmarkdown)
library(knitr)
render("eqn-numbering.Rmd")
@dewittpe
dewittpe / README.md
Last active April 14, 2017 03:08
icd_explorations

ICD Exploration

Exploring the ICD codes between the icd package and the pccc package.

In general there are R scripts which are used to produce .md files via knitr::spin()

@dewittpe
dewittpe / Data.csv
Created May 23, 2017 16:50
data-for-so44096820
date value
1995-01-01 100
1995-02-01 98.9
1995-03-01 97.8
1995-04-01 97.9
1995-05-01 98.2
1995-06-01 104.4
1995-07-01 101.1
1995-08-01 101.9
1995-09-01 103.3
@dewittpe
dewittpe / my_extractor.R
Last active October 27, 2017 17:20
Custom extractor function
# my_extractor.R
#
# Given an M dimensional array, extract the last index based on prescribed
# values of the first M-1 values.
#
# For example, for a 3D array with indices [x, y, z] write a function that will
# extract z as function of x and y.
set.seed(42)