Skip to content

Instantly share code, notes, and snippets.


Martin Monkman MonkmanMH

View GitHub Profile
View penguins_quantcut.R
penguins <- palmerpenguins::penguins
penguins %>%
filter(! %>%
mutate(bm_quart = gtools::quantcut(body_mass_g, q=4))
penguins_2 <- penguins %>%
filter(! %>%
select(species, sex, body_mass_g) %>%
# mutate(bm_quart = gtools::quantcut(body_mass_g, q=4))
MonkmanMH /
Last active Oct 7, 2020
git command to rename branch of repo

rename from "master" to "main"

git branch -m master main

push to github

git push -u origin main

and delete the original

git push origin --delete master can do this as an Rmd with the git commands in a bash chunk

View rename_master_to_main.Rmd
title: "rename github repo"
author: "Martin Monkman"
date: "2020/10/05"
output: html_document
MonkmanMH / annotater_install.R
Created Oct 6, 2020
install {annotater} package
View annotater_install.R
# short script to install the {annotater} package
# reference:
# Step 1: install the {remotes} package
# Step 2: install {annotater} from the GitHub source
MonkmanMH / gist:7740998
Last active Sep 6, 2020
Random number generation in R (rstats, #rstats)
View gist:7740998

Random numbers in R

The creation of random numbers, or the random selection of elements in a set (or population), is an important part of statistics and data science. From simulating coin tosses to selecting potential respondents for a survey, we have a heavy reliance on random number generation.

R offers us a variety of solutions for random number generation; here's a quick overview of some of the options.

runif, rbinom, rnorm

One simple solution is to use the runif function, which generates a stated number of values between two end points (but not the end points themselves!) The function uses the continuous uniform distribution, meaning that every value between the two end points has an equal probability of being sampled.

View postal_code_loop.R
# dplyr::case_when to find and clean FSA
# Notes:
# * FSA = "Forward Sortation Area" in Canadian postal parlance
# * the regex finds British Columbia FSAs (starting with "V")
FSA_list <- df %>%
mutate(FSA_clean = case_when(
str_detect(FSA, "V\\d.$") == TRUE ~ FSA,
TRUE ~ NA_character_
MonkmanMH / geom_bar_col.Rmd
Created Apr 19, 2020
geom_bar vs geom_col
View geom_bar_col.Rmd
title: "geom_col vs geom_bar"
author: "Martin Monkman"
date: "2020/04/19"
output: html_document
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
MonkmanMH / transform_data_solutions.Rmd
Created Nov 4, 2019
Answer key for tidyverse transform data exercises
View transform_data_solutions.Rmd
title: "Transform Data"
subtitle: "hands-on examples, with answers"
output: html_notebook
<!-- This file by Charlotte Wickham (with some modifications by Martin Monkman) is licensed under a Creative Commons Attribution 4.0 International License, adapted from the orignal work at by RStudio and -->
```{r setup}
MonkmanMH / gist:9190970
Last active Sep 12, 2019
Categorical data analysis in R - a resource list
View gist:9190970
View goalsscored.R
### ---
# from @expersso
set.seed(894) # number of regular season NHL goals Wayne Gretzky scored
x <- replicate(10000, sum(sample(0:1, 20, TRUE, c(0.945, 0.055))))
table(ifelse(x == 0, "Team A win", ifelse(x == 1, "Draw", "Team B win"))) / 100
You can’t perform that action at this time.