This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The incantation | |
options(stringsAsFactors = FALSE) | |
library(ggplot2) | |
# Some sample data | |
# A test that can result in a negative or positive only | |
testres2 <- data.frame(result = c("Negative", "Positive"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM This file converts all of the Markdown files to HTML. | |
REM Main files | |
for %%i in (main/*.markdown) do pandoc -f markdown -t html5 main/%%~ni.markdown links.markdown > html/main/%%~ni.html | |
REM Report pages | |
for %%i in (report_pages/*.markdown) do pandoc -f markdown -t html5 report_pages/%%~ni.markdown links.markdown > html/report_pages/%%~ni.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<style> | |
td { | |
text-align: left; | |
border: 1px solid #808080; | |
} | |
h4 { | |
background-color: #1F78B4; | |
color: #FFFFFF; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate age at a given reference date | |
# Create an interval between the date of birth and the enrollment date; | |
# intervals are specific to the two dates. Periods give the actual length | |
# of time between those dates, so convert to period and extract the year. | |
calc_age <- function(birthDate, refDate = Sys.Date(), unit = "year") { | |
require(lubridate) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git show commit-id:filename | vim - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the date of the last day of a given quarter by pasting | |
# together its first day, adding three months, and subtracting a day. | |
# Very elegance | |
# Such vectorized | |
calc_qtr_end <- function(year, qtr) { | |
require(lubridate) # Easiest way to add a month to a date | |
(as.Date(paste(year, qtr * 3, "01", sep = "-")) %m+% months(1)) - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@media print { | |
tr{ | |
page-break-after: always; | |
display: block; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample data | |
X <- data.frame( | |
x = c(1, 2, 3), | |
y = c(4, 5, 6), | |
etc = c("a", "b", "c") | |
) | |
# Arbitrary stand-in for function that can't be vectorized (no pmax) | |
max.fun <- function(a, b) { max(c(a, b)) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(zoo) | |
# Some sequence of Dates | |
x <- as.Date("2014-01-01") + c(0, 1, 2, 5, 10) | |
data.frame(x, | |
basediff = c(NA, diff(x)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dummy list | |
z <- list(list('a' = 1, 'b' = 2, 'c' = 3), list('a' = 4, 'b' = 5, 'c' = 6)) | |
# If you just want to stack all of the values, not keeping any of the list name data | |
# but ensuring they're all of one type | |
data.frame(values = as.numeric(unlist(z))) | |