Skip to content

Instantly share code, notes, and snippets.

View MilesMcBain's full-sized avatar

Miles McBain MilesMcBain

  • Queensland Fire and Emergency Services
  • Brisbane, Queensland
View GitHub Profile
@MilesMcBain
MilesMcBain / patch.R
Created March 10, 2016 01:52 — forked from dholstius/patch.R
Patch data on-the-fly (DRAFT)
#' Patch data on the fly.
#'
#' @param object to be patched
#' @param cond logical condition(s) to be evaluated within scope of object
#' @param \dots name-value pairs
#' @param quiet suppress messages
#'
#' @examples
#' patch(mtcars, where(vs == 0, am == 1), gear = Inf, carb = carb + 10)
#'
@MilesMcBain
MilesMcBain / ipython-notebook.conf
Last active December 12, 2017 16:35 — forked from whophil/ipython-notebook.conf
Upstart file (Ubuntu) for Jupyter / IPython notebook
start on filesystem or runlevel [2345]
stop on shutdown
description "Jupyter / IPython Notebook Upstart script"
script
export HOME="/home/ubuntu/"; cd $HOME
echo $$ > /var/run/ipython_start.pid
exec su -s /bin/sh -c 'exec "$0" "$@"' ubuntu -- /home/ubuntu/anaconda2/bin/jupyter-notebook --config='/home/ubuntu/.jupyter/jupyter_notebook_config.py'
end script
@MilesMcBain
MilesMcBain / nginx.conf
Last active June 4, 2016 07:18
nginx forwarding for jupyter, rstudio
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file
server{
#server_name localhost;
listen 80;
location / {
@MilesMcBain
MilesMcBain / cost_of_groups_dplyr.R
Last active July 6, 2016 00:34
A demonstration the effect of increasing number groups on mutate() in dplyr.
library(ggplot2)
library(dplyr)
system.time({
nycflights13::flights %>%
mutate(timestring = lubridate::date(time_hour))
})
#0 groups
# user system elapsed
# 0.048 0.000 0.047
---
title: "Plotly Slideshow Example"
author: "Miles McBain"
date: "6 August 2016"
output:
ioslides_presentation
---
```{r, include=FALSE}
library(AER)
library(ggplot2)
---
title: "Comment Example"
author: "Miles McBain"
date: "4 September 2016"
output:
html_document:
css: https://cdn.rawgit.com/MilesMcBain/rmarkdown_comment/master/review.css
---
#Hadley Gapminder Way
nested_iris <-
iris %>%
mutate(Setosa = ifelse(Species == "Setosa", yes=1, no=0) ) %>%
select(-Species) %>%
gather(key="measure", value="value", Sepal.Length:Petal.Width) %>%
nest(Setosa, value)
iris_models <- map(nested_iris$data, ~ glm(data=.,
formula = Setosa ~ value,
#Remove things in the global environment with name like a string you supply.
#Like is in the regex match sense, so if you make a slip blowing away most of your environment is possibility.
rm_like <- function(pattern = character()) {
rm( list = grep(pattern = pattern,
x=ls(envir = globalenv()),
value = TRUE),
envir = globalenv()
)
}
library(readr)
library(dplyr)
library(caret)
# from: https://archive.ics.uci.edu/ml/machine-learning-databases/00222/
bank_data <- read_delim("~/Downloads/bank-additional/bank-additional/bank-additional-full.csv", delim=";")
bank_data <- bank_data[-caret::nearZeroVar(bank_data)]
dummy_var_obj <-
bank_data %>%
caret::dummyVars(formula = y ~ .,
library(alr3)
library(purrr)
library(dplyr)
library(broom)
library(modelr)
challenger_data <- challeng
link <- c("logit", "probit", "cloglog")
formulas <- formulas(.response = ~ cbind(Fail, n-Fail),