Skip to content

Instantly share code, notes, and snippets.

View deanmarchiori's full-sized avatar

Dean Marchiori deanmarchiori

View GitHub Profile
@deanmarchiori
deanmarchiori / army_military_fatalities.R
Last active August 31, 2022 21:42
Army Military Fatalities
# source: https://twitter.com/internetdepths/status/1564949689962827776
library(tibble)
tibble(
year = 1993:2003,
fatalities = c(237, 233, 209, 194, 150, 168, 187, 161, 168, 202, 255),
rate_per_thous_soldiers = c(0.35, 0.36, 0.34, 0.33, 0.26, 0.29, 0.33, 0.28, 0.28, 0.34, 0.38)
)
@deanmarchiori
deanmarchiori / complete.r
Created August 13, 2020 06:06
Turning implicit missing values into explicit missing values.
# tidyr::complete() & tidyr::full_seq() -----------------------------------
# Turning implicit missing values into explicit missing values.
# Bonus: Filling in gaps in a date range
library(tidyr)
library(tibble)
library(dplyr)
# Making up some observations from two weather stations.
@deanmarchiori
deanmarchiori / nsw_fire_map.R
Last active October 11, 2020 05:21
Mapping NSW Current Incidents in R
# Mapping NSW Current Incidents in R -------------------------------------------
library(sf)
library(mapview)
library(tidyverse)
#' Current Incidents Feed (GeoJSON)
#' This feed contains a list of current incidents from the NSW RFS,
#' and includes location data and Major Fire Update summary information where available.
#' Click through from the feed to the NSW RFS website for full details of the update.
@deanmarchiori
deanmarchiori / beta_plot.R
Created July 15, 2019 03:42
Easy Beta distribution plots in base R - auto scaling axes
beta_plot <- function(shape_1 = 1, shape_2 = 1,
x_min = qbeta(0.0001, shape_1, shape_2),
x_max = qbeta(0.9999, shape_1, shape_2)){
x <- seq(x_min, x_max, length.out = 1000)
y <- dbeta(x, shape_1, shape_2)
plot(x, y,
type = "l",
ylab = "density",
xlab = "probability",
main = paste0("Beta(", shape_1, ", ", shape_2, ")"))
@deanmarchiori
deanmarchiori / nthdayofmonth.R
Created August 28, 2018 23:30
Finds the nth weekday of a given month and year
nthdayofmonth <- function(year, month, day, nth = 1){
#' Finds the nth weekday of a given month and year
#'
#' Enter the year or years, month, and weekday along with the nth
#' weekday of the month you are interested in.
#'
#' @param year Character Vector. Year/s of interest
#' @param month Character. The numeric month i.e. "11" for November
#' @param day Character. The full weekday of interest, will do partial
#' matching.
@deanmarchiori
deanmarchiori / cluster_workflow.r
Created January 17, 2018 23:48
This is a customised workflow for performing cluster analysis
#####################################################
# CLUSTER WORKFLOW #
#####################################################
#' This is a customised workflow for performing cluster analysis
#' under the following conditions:
#' - Mixed Data Type.
#'
#' How it works:
#' 1. Reads in an R data file eg. .RDS