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 / 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 ~ .,
tribble(
~Aus.City, ~Pop,
"Sydney", "4920970",
"Melbourne", "4529496",
"Brisbane", "2308720",
"Perth", "2039193",
"Adelaide", "1316779",
"Gold Coast", " 624918",
"Newcastle", " 434454",
"Canberra", " 424666"
library(tibble)
library(ggplot2)
library(dplyr)
library(ggrepel)
library(ggthemes)
stackR <- tribble(
~Aus.City, ~R, ~TotalVisits, ~Pop,
"Melbourne", "23176", "1544868", "4529496",
"Adelaide", "7181", "350850", "1316779",