Skip to content

Instantly share code, notes, and snippets.

View trinker's full-sized avatar

Tyler Rinker trinker

View GitHub Profile
@MrFlick
MrFlick / test.withX.R
Last active August 29, 2015 14:01
withX.R: Allows you to perform multiple operations on a temporary object without having to create a temporary variable
# withX() will create an environment for the first parameter and all of your named parameters
# if the first parameter is not named, it will be called "X" in the enviroment
# there may be exactly one unnamed expression
# this unnamed parameter will be eval'ed in the envir defined by your named parameters
# If no object is returned from the expression, the newest value of the first parameter is returned invisibly
# this can avoid repeating awkward expressions
#this is a lot like `with()` but instead of working within the variable,
# the value itself is added to the enviroment as a variable
@bryangoodrich
bryangoodrich / RegularizedGradientDescent.R
Created August 26, 2014 05:45
Regularized Gradient Descent Logistic Classifier with Decision Boundary
loadInput <- function() {
structure(c(0.051267, -0.092742, -0.21371, -0.375, -0.51325,
-0.52477, -0.39804, -0.30588, 0.016705, 0.13191, 0.38537, 0.52938,
0.63882, 0.73675, 0.54666, 0.322, 0.16647, -0.046659, -0.17339,
-0.47869, -0.60541, -0.62846, -0.59389, -0.42108, -0.11578, 0.20104,
0.46601, 0.67339, -0.13882, -0.29435, -0.26555, -0.16187, -0.17339,
-0.28283, -0.36348, -0.30012, -0.23675, -0.06394, 0.062788, 0.22984,
0.2932, 0.48329, 0.64459, 0.46025, 0.6273, 0.57546, 0.72523,
0.22408, 0.44297, 0.322, 0.13767, -0.0063364, -0.092742, -0.20795,
-0.20795, -0.43836, -0.21947, -0.13882, 0.18376, 0.22408, 0.29896,
@jennybc
jennybc / 2014-09-18_numeric-index-gotcha.md
Last active August 29, 2015 14:06
How quickly indexing with numeric can burn you

Inspired by recent @johnmyleswhite tweets on indexing (though they focus more on NA stuff)

My standard advice to R novices is "don't worry about numeric vs integer too much, for now", but I just created an indexing example that scares me.

I did not realize it was sooo easy to create this gotcha when indexing with numeric (which I know is not a great idea).

@pdparker
pdparker / knitr
Last active August 29, 2015 14:15
knitr makefile
# Transform .Rmd files to slidy files
.SUFFIXES: .Rmd .html .md
all: Day1Part1-Introduction.md Day1Part1-Introduction.html Day1Part1-session2.md Day1Part1-session2.html \
Day1Part1-session3.md Day1Part1-session3.html Day1Part2-session1.md Day1Part2-session1.html \
Day1Part2-session2.md Day1Part2-session2.html
#markdown
%.md: %.Rmd
@bryangoodrich
bryangoodrich / PercolationModel.py
Created March 17, 2015 06:42
Using Union-Find Data Structure to Model Percolation System
import array
class WeightedQuickUnion:
def __init__(self, N):
self.count = N
self.id = array.array('i', range(N))
self.size = array.array('i', [1] * N)
def connected(self, p, q):
return self.find(p) == self.find(q)
```r
p_load_gh("jcheng5/bubbles", "trinker/qdapTools")
x <- runif(26)
colfunc <- colorRampPalette(c("white", "red"))
cols <- colfunc(length(sort(unique(x))))
bubbles(value = x, label = LETTERS,
@abresler
abresler / netsdaily_polarity_plot
Last active December 18, 2015 15:17
Netsdaily Polarity Plot in R
### Parsing Netsdaily for a Polarity Plot -- working with JSON
packages <-
c('magrittr', 'dplyr', 'qdap', 'jsonlite', 'ggplot2')
lapply(packages, library, character.only = T)
url <-
'http://www.netsdaily.com/comments/load_comments/8261850'
data <-
url %>%
@leeper
leeper / slopegraph.r
Last active December 26, 2015 13:29
Edward Tufte-style Slopegraphs in R. Find the current version of this code here: https://github.com/leeper/slopegraph
# R Function to Draw Edward Tufte-style Slopeplots
slopegraph <-
function(
df,
xlim = c(.5,ncol(df)+.5),
ylim = c(min(df)-diff(range(df))/100,max(df)+diff(range(df))/100),
main = NULL,
bty = 'n',
yaxt = 'n',
library(idbr)
library(ggplot2)
library(gganimate)
library(tweenr)
library(countrycode)
library(dplyr)
idb_api_key("Your API key goes here")
africa_fips <- countrycode(c('Nigeria', 'Uganda', 'Tanzania', 'Ghana'),
library(gh)
library(tidyverse)
library("magick")
library(glue)
dir.create("data")
repos <- gh::gh("/orgs/:org/repos", org = "tidyverse", .limit = Inf) %>% map_chr("name")
urls <- repos %>%