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
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)))
remove(list=ls())
require(jsonlite)
require(ggplot2)
require(reshape2)
require(scales)
jr=theme(panel.background = element_rect(fill = NA, colour = "black", size = 0.25),
panel.border = element_blank(),
panel.grid.major = element_line(colour = "black", size = 0.05),
panel.grid.minor = element_line(colour = "black", size = 0.05),
## LOAD LIBRARIES
library(dplyr)
library(tidyr)
library(httr)
library(readxl)
## CUSTOM FUNCTION TO READ ALL SHEETS OF AN EXCEL FILE INTO A LIST OF DATA FRAMES OR TIBBLES THANKS STACK OVERFLOW!!
## https://stackoverflow.com/questions/12945687/read-all-worksheets-in-an-excel-workbook-into-an-r-list-with-data-frames
read_excel_allsheets <- function(filename, tibble = FALSE) {
sheets <- excel_sheets(filename)