Skip to content

Instantly share code, notes, and snippets.

@johnmackintosh
johnmackintosh / Coin flips.R
Created October 30, 2016 08:53
Probability of n consecutive heads in a row from successive coin flips
library(ggplot2)
library(ggrepel)
library(scales)
library(ggExtra)
library(ggthemes)
n<- c(1:10)
flips<- 2*(2^n-1) #number of coin flips required
prob <- 0.5^n # probability of achieving n in a row
percentage<-(round(prob,4)*100)
@johnmackintosh
johnmackintosh / jekyll blog links.txt
Last active November 26, 2016 22:54
Help for jekyll blogging
@johnmackintosh
johnmackintosh / blogyamlheaders.yml
Created January 14, 2017 21:09
yaml header template for blog posts
---
layout: post
published: false
title: #Insert title here
subtitle: #Insert sub here
tags:
- rstats
- R
- r-bloggers
date: '2017-01-02'
@johnmackintosh
johnmackintosh / wrapr let.R
Last active June 1, 2017 05:35
Investigating the wrapr let function
##### set up#######
library(dplyr)
library(wrapr)
data<-structure(list(Location = c("AreaZ", "AreaZ", "AreaZ", "AreaZ",
"AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ",
"AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ",
## see http://johnmackintosh.com/2017-06-01-UPDATED-let-there-be-progress/ for background
#### direct from the expert - code kindly provided via blog comment by John Mount, Win-Vector LLC
library("dplyr")
library("wrapr")
d <- data.frame(
location = c('AreaZ', 'AreaZ', 'AreaZ', 'AreaW', 'AreaW', 'AreaW'),
@johnmackintosh
johnmackintosh / nhshsepsis.R
Last active November 7, 2017 18:27
trying out rtweet package R
library(rtweet)
library(tidyverse)
library(dplyr)
library(hrbrthemes)
library(extrafont)
library(viridis)
## create token named "twitter_token"
twitter_token <- create_token(
app = appname,
@johnmackintosh
johnmackintosh / fixings.r
Last active January 25, 2018 21:22
Data driven DIY decisions using R
library(readr)
library(ggplot2)
library(dplyr)
library(ggrepel)
data <- read_delim(
"Fixings.txt", "\t", escape_double = FALSE,
trim_ws = TRUE)
@johnmackintosh
johnmackintosh / windowing and sequence number.sql
Last active May 31, 2018 23:55
final nested query for row of dots
SELECT y.MovementDateTime,
y.FirstName,
y.LastName,
y.Ward_Dept,
y.Staging_Post,
y.Movement_Type,
y.IN_OUT,
y.Movement15,
y.[counter],
y.[counter] * y.R_Number AS Movement_15_SEQNO
@johnmackintosh
johnmackintosh / windowing example.sql
Last active May 31, 2018 23:58
windowing query for row of dots to enable cumulative count
SELECT x.[MovementDateTime],
x.[FirstName],
x.[LastName],
x.[Ward_Dept],
x.[Staging_Post],
x.[Movement_Type],
x.[IN_OUT],
x.[Movement15],
x.[counter],
ROW_NUMBER() OVER (PARTITION BY IN_OUT, Movement_Type,Staging_Post,Movement15 ORDER BY (MovementDateTime))AS R_Number
@johnmackintosh
johnmackintosh / succinct.sql
Created June 3, 2018 21:40
more succint version of sql example from row of dots post
SELECT * ,
ROW_NUMBER() OVER (PARTITION BY IN_OUT, Movement_Type,Staging_Post,Movement15 ORDER BY (MovementDateTime)) * [counter] AS Movement_15_SEQNO
FROM (
SELECT [MovementDateTime],
[FirstName],
[LastName],
[Ward_Dept],
[Staging_Post],
[Movement_Type],
[IN_OUT],