Skip to content

Instantly share code, notes, and snippets.

@stillmatic
stillmatic / graphdata.json
Last active August 29, 2015 14:04
loading grouped graph data from json
[
{
"x": "2014-06-11",
"y": 20,
"group": 1
},
{
"x": "2014-06-12",
"y": 25,
"group": 1
#2012
load("C:/120/wptp/sesh1.RData")
attach(newdata);
with(newdata, plot(I.formed.a.positive.relationship.with.my.tutee.. ~ Semesters))
with(newdata, plot(Semesters ~ Academic.Year))
with(newdata, plot(Are.you.a.section.leader. ~ Academic.Year))
.f = function(
lm(Tutor.at.the.same.site ~ My.tutee.benefited.from.tutoring.sessions..)
#Intercept: 0.1694 Coeff: 0.1565
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../paper-item/paper-item.html">
@stillmatic
stillmatic / baseball.r
Last active August 29, 2015 14:19
employ lahman library and build model for hall of fame election
# mlb hall of fame classification analysis
# chua@wharton.upenn.edu
# attempt to follow https://google-styleguide.googlecode.com/svn/trunk/Rguide.xml
rm(list=ls())
par(mfrow=c(1,1))
if (!require("pacman")) install.packages("pacman")
pacman::p_load("Lahman", "dplyr", "ggplot2")
@stillmatic
stillmatic / pitcherVis.r
Created April 28, 2015 04:17
compare pre and post 1950 pitchers
# chua@wharton.upenn.edu
## my cached version may be slightly different than the live version loaded by this file
if (!require("pacman")) install.packages("pacman")
pacman::p_load("Lahman", "dplyr")
batting <- summarize(group_by(Batting, playerID),
ab=sum(AB, na.rm=TRUE), r=sum(R, na.rm=TRUE),
h=sum(H, na.rm=TRUE), x2b=sum(X2B, na.rm=TRUE),
x3b=sum(X3B, na.rm=TRUE), hr=sum(HR, na.rm=TRUE),
@stillmatic
stillmatic / clean-hitters.r
Last active August 29, 2015 14:20
lahman get started code
# mlb hall of fame classification analysis
# chua@wharton.upenn.edu
rm(list = ls())
par(mfrow = c(1, 1))
if (!require("pacman")) install.packages("pacman")
pacman::p_load("Lahman", "dplyr", "ggplot2")
# get career batting totals
@stillmatic
stillmatic / slide_apply.r
Last active August 12, 2016 04:37
Like zoo::rollapply but faster
##########
#' Applies a function to subsets of a given dataset.
#' Note: sets values without sufficient data to NA.
#' Using 'step' is particularly useful for leave-one-out analysis.
#'
#' @export
#' @name slide_apply
#' @author \href{https://github.com/stillmatic}{Chris Hua}
#' @title Use apply over a sliding window of data
#' @param data Array of data to apply the function over.
@stillmatic
stillmatic / grids.r
Last active August 29, 2015 14:23
r - square gridding
# simple utility function to plot a bunch of graphs in a square-ish fashion
findOptArrangement <- function(k) {
# k: number of plots to arrange
# given k, find most square-like arrangement of the data
s <- sqrt(k)
f <- floor(s)
if(s %% 1 == 0 ) {
par(mfrow=c(s,s))
} else {
This file was created by CMPT_ME_BEME_RETS_DAILY using the 201602 CRSP database.
The Tbill return is the simple daily rate that, over the number of trading days
in the month, compounds to 1-month TBill rate from Ibbotson and Associates Inc.
Copyright 2016 Kenneth R. French
Date Mkt-RF SMB HML RF
20060920 0.60 0.59 -0.22 0.020
20060921 -0.59 -0.42 0.12 0.020
20060922 -0.41 -0.85 0.45 0.020
a <- data.frame("day" = c(1,5,2), "person" = c("A", "B", "C"))
b <- data.frame("day" = rep(1:7, 3), "person" = c(rep("A", 7), rep("B", 7), rep("C",7)))
b$t0 <- rep(0, nrow(b))
for(i in 1:nrow(a)) {
b$t0[which(b$person == a$person[i])] <- a$day[i]
}
b
# this was a stupid thought exercise