Skip to content

Instantly share code, notes, and snippets.

View johnmackintosh's full-sized avatar

John MacKintosh johnmackintosh

View GitHub Profile
@johnmackintosh
johnmackintosh / scotland-cusums.R
Created December 15, 2021 22:43
rolling 28 day positive case counts in Scotland council areas using PHS open data and {cusumcharter}
library(dplyr)
library(data.table)
library(ggplot2)
library(cusumcharter)
library(purrr)
library(tidyr)
library(ggExtra)
# make the link dynamic
@johnmackintosh
johnmackintosh / interpolation2.R
Created October 20, 2021 22:25
no nonsense interpolation of integer as part of SQL SERVER dateadd function in R
ndays <- 7
ndays_sql <- ndays * -1
con <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "SERVER",
Database = "TABLE",
Trusted_Connection = "True",
Port = 1433)
@johnmackintosh
johnmackintosh / data.table-joins.R
Created March 2, 2021 23:27 — forked from nacnudus/data.table-joins.R
How to do joins with data.table
library(data.table)
?`[.data.table`
DT <- data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6), v=1:9)
X <- data.table(x=c("c","b"), v=8:7, foo=c(4,2))
colnames(DT)
# [1] "x" "y" "v"
@johnmackintosh
johnmackintosh / PBI.txt
Created January 31, 2021 20:22
Power BI resources
----
Power BI Official Software - Cost: $0 Dimes
----
Power BI Desktop. From the Microsoft Store updates automatically. #WINNING
URL: https://aka.ms/pbidesktopstore
Power BI Desktop. From download center requires manual updating. #NOTWINNING
library(lubridate)
library(dplyr)
library(tidyr)
library(readxl)
library(purrr)
library(here)
setwd(here("2021-04"))
wb <- "PD 2021 Wk 4 Input.xlsx"
library(lubridate)
library(dplyr)
library(tidyr)
library(readxl)
library(purrr)
library(here)
setwd(here("2021-03"))
library(here)
library(data.table)
library(stringr)
setwd(here("2021-02"))
# read in and process
DT <- fread('Input.csv')
library(data.table)
library(gsheet)
library(ggplot2)
link <- 'https://docs.google.com/spreadsheets/d/1GYv4573GnJa-C21NYeDj-OhFSTwrK0SnQNF2IQFqa50/edit#gid=0'
import <- gsheet2text(link, format = 'tsv')
DT <- fread(import)
DT[, Date := as.IDate(DT$Date, format = "%d/%m/%Y")]
@johnmackintosh
johnmackintosh / automate blog years.txt
Created January 1, 2021 12:29
Update the year in the copyright notice of blog post automatically
<script>document.write(new Date().getFullYear())</script>
or
<script>new Date().getFullYear()>2005&&document.write("-"+new Date().getFullYear());</script>
@johnmackintosh
johnmackintosh / link.txt
Created June 14, 2020 23:14
Great package/ OOP guide