Skip to content

Instantly share code, notes, and snippets.

View jonrobinson2's full-sized avatar

Jonathan Robinson jonrobinson2

View GitHub Profile
# color.column - color the columns of a table for LaTeX output.
#
# Takes an xtable object and a column name as input, and returns the
# xtable with the chosen column stringified and prepended with color
# values using the \cellcolor command from the xcolor package. For an
# easy copy-paste into a LaTeX document, use xtable's print function
# with the following parameter to preserve the \cellcolor command:
# "sanitize.text.function=function(x){x}". I also like to add
# "include.rownames=F". Here's a worked example:
#
# sql.export.gbm(): save a GBM model as SQL
# v0.11
# Copyright (c) 2013-2014 Shane Butler <shane dot butler at gmail dot com>
#
# sql.export.gbm is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# sql.export.gbm is distributed in the hope that it will be useful, but
# sql.export.rf(): save a randomForest model as SQL
# v0.03
# Copyright (c) 2013-2014 Shane Butler <shane dot butler at gmail dot com>
#
# sql.export.rf is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# sql.export.rf is distributed in the hope that it will be useful, but
require(pollstR)
require(ggplot2)
require(magrittr)
remove(list=ls())
tmp=pollstr_polls(max_pages = 10000, chart = '2016-national-gop-primary', after = "2015-3-1")
tmp$questions=tmp$questions[tmp$questions$topic=='2016-president-gop-primary',]
tmp1=merge(tmp$polls, tmp$questions, by='id')
require(httr)
require(jsonlite)
require(ggplot2)
require(gridExtra)
remove(list=ls())
hm=fromJSON('http://stats.nba.com/stats/teamgamelog?LeagueID=00&Season=2015-16&SeasonType=Regular+Season&TeamID=1610612764')
wiz=data.frame(hm$resultSets$rowSet)
require(rvest)
require(lubridate)
require(stringr)
require(ggplot2)
age = function(from, to) {
from_lt = as.POSIXlt(from)
to_lt = as.POSIXlt(to)
age = to_lt$year - from_lt$year
@jonrobinson2
jonrobinson2 / cavs.R
Created May 6, 2016 00:54
Quick and Dirty not too pretty season stats
require(httr)
require(jsonlite)
require(ggplot2)
require(gridExtra)
require(directlabels)
cavs_reg=fromJSON('http://stats.nba.com/stats/teamgamelog?LeagueID=00&Season=2015-16&SeasonType=Regular+Season&TeamID=1610612739')
cavs_playoffs=fromJSON('http://stats.nba.com/stats/teamgamelog?LeagueID=00&Season=2015-16&SeasonType=Playoffs&TeamID=1610612739')
cavs=data.frame(cavs_reg$resultSets$rowSet)
remove(list=ls())
require(googlesheets)
require(dplyr)
require(stringr)
#options(error = expression(NULL))
list_sheets=gs_ls()
wedding_list=gs_title("Jonarobin Master Wedding List")
require(arm)
set.seed(987654321)
.tmp=(rnorm(100000, mean=0))
.tmp=invlogit(.tmp)
shift_param=.3
par(mfrow=c(1,3))
hist(x=.tmp, main=paste0('Mean=',round(mean(.tmp),3)))
require(data.table)
require(sqldf)
require(rvest)
require(dplyr)
fairvote=read_html('https://infogram.com/cong-primaries-by-party-1g0n2owgxvyrp4y') %>%
html_nodes('script') %>%
html_text()
fairvote=fairvote[[7]]
fairvote=unlist(strsplit(x = fairvote,fixed = T, split = c('[\"','\"]')))