Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Multi-tasking

Martin Monkman MonkmanMH

🎯
Multi-tasking
View GitHub Profile
@MonkmanMH
MonkmanMH / gist:8798762
Last active Aug 29, 2015
Percentile function in R
View gist:8798762
# CALCULATING PERCENTILES IN R
#
# a basic percentile function using "ecdf" [Empirical Cumulative Distribution Function]
# using a data file "percentiledata" with variable VALUE
percentileFUN <- ecdf(percentiledata$VALUE)
percentileFUN
percentileFUN(percentiledata$VALUE)
# write the percentile values to the source file
percentiledata$pctl <- percentilefunction(percentiledata$VALUE)
#
@MonkmanMH
MonkmanMH / gist:3c0da6afd58eb61e2c51
Last active Aug 29, 2015
dplyr testing and goofing
View gist:3c0da6afd58eb61e2c51
#
# setwd("D:/R_the software/datatrials/Lahman")
#
require(Lahman)
require(dplyr)
#
# throwing by position
# version 1 - "merge"
MasterFielding <- data.frame(merge(Master, Fielding, by="playerID"))
MasterFielding <- merge(Master, Fielding, by="playerID")
@MonkmanMH
MonkmanMH / gist:0f92cba504f2e7f11bba
Created Jul 29, 2014
Wes Anderson palette in R
View gist:0f92cba504f2e7f11bba
if (!require(wesanderson)) install.packages("wesanderson")
library(wesanderson)
# for more on the Wes Anderson colour palette:
# https://github.com/karthik/wesanderson#wes-anderson-palettes
# http://blog.revolutionanalytics.com/2014/03/give-your-r-charts-that-wes-anderson-style.html
#
#
#
# add some Wes Anderson "Grand Budapest Hotel" colour to print object "p2"
p2 + scale_fill_manual(values = wes.palette(4, "GrandBudapest"))
View gist:efdf9c772054131ca22f
---
title: "Testing Lahman 3.0"
author: "Martin Monkman"
date: "Sunday, August 31, 2014"
output: html_document
---
This markdown document incorporates a variety of short scripts that draw on the various tables in the `Lahman` package. (See the Lahman project page on RForge for more details <http://lahman.r-forge.r-project.org/>.)
Note that some of scripts appear in the documentation of other R packages; in those cases, the original source is noted prior to the script.
@MonkmanMH
MonkmanMH / gist:4720641
Last active Dec 12, 2015
MLB runs per game per team
View gist:4720641
# THE HISTORICAL RECORD - RUNS PER GAME BY TEAM
#
# public Gist of this code can be found at
# https://gist.github.com/MonkmanMH/4720641
#
# data source: Lahman Database
# http://www.seanlahman.com/baseball-archive/statistics/
# 2012 version (1871-2012)
# data table "Teams.csv"
#
@MonkmanMH
MonkmanMH / gist:4969818
Last active Dec 13, 2015
MLB team runs per game
View gist:4969818
# INDIVIDUAL TEAM HISTORY
#
# discussion and output can be found at
# http://bayesball.blogspot.ca/XXXXXXXXXXXXXXXXXXXXX
#
# Select the team you want from the franchID variable in the Teams.merge data frame
# and create a new data frame called "Team1"
# For this exercise we will use the Seattle Mariners, which are coded as SEA
# Note the use of double "=" to define the team!
Team1 <- as.data.frame(subset (Teams.merge, franchID == "SEA"))
@MonkmanMH
MonkmanMH / gist:4970480
Created Feb 17, 2013
MLB runs per game - league trends
View gist:4970480
# MAJOR LEAGUE BASEBALL - RUNS PER GAME TREND
#
# discussion at
# 1. http://bayesball.blogspot.ca/2012/07/trends-in-al-run-scoring-using-r.html
# 2. http://bayesball.blogspot.ca/2012/07/trends-in-run-scoring-nl-edition-more-r.html
# 3. http://bayesball.blogspot.ca/2012/08/trends-in-run-scoring-comparing-leagues.html
#
# data source: Baseball Reference
# http://www.baseball-reference.com
# http://www.baseball-reference.com/leagues/AL/bat.shtml
@MonkmanMH
MonkmanMH / gist:5027789
Created Feb 25, 2013
MLB runs per game - league average
View gist:5027789
# THE HISTORICAL RECORD - RUNS PER GAME
#
# discussion and output can be found at
# http://bayesball.blogspot.ca/2013/02/comparing-individual-team-run-production.html
#
# data source: Lahman Database
# http://www.seanlahman.com/baseball-archive/statistics/
# 2012 version (1871-2012)
# table: "Teams"
#
@MonkmanMH
MonkmanMH / gist:5027793
Created Feb 25, 2013
MLB team history - runs allowed
View gist:5027793
# INDIVIDUAL TEAM HISTORY - RUNS ALLOWED
#
# select the team you want from the franchID variable in the Teams.merge data frame
# and create a new data frame called "Team1"
# note the use of double "=" to define the team!
Team1 <- as.data.frame(subset (Teams.merge, franchID == "SEA"))
#
# create what will be the chart title from the contents of Team1
# note that teams sprang into existence in different years, thus the requirement to define both the start and end dates
firstyear <- Team1$yearID[1]
You can’t perform that action at this time.