Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Multi-tasking

Martin Monkman MonkmanMH

🎯
Multi-tasking
View GitHub Profile
View penguins_quantcut.R
penguins <- palmerpenguins::penguins
penguins %>%
filter(!is.na(sex)) %>%
mutate(bm_quart = gtools::quantcut(body_mass_g, q=4))
penguins_2 <- penguins %>%
filter(!is.na(sex)) %>%
select(species, sex, body_mass_g) %>%
# mutate(bm_quart = gtools::quantcut(body_mass_g, q=4))
View rename_master_to_main.Rmd
---
title: "rename github repo"
author: "Martin Monkman"
date: "2020/10/05"
output: html_document
---
From
https://www.r-bloggers.com/2020/07/5-steps-to-change-github-default-branch-from-master-to-main/
@MonkmanMH
MonkmanMH / annotater_install.R
Created Oct 6, 2020
install {annotater} package
View annotater_install.R
# short script to install the {annotater} package
# reference: https://github.com/luisDVA/annotater
# Step 1: install the {remotes} package
install.packages("remotes")
# Step 2: install {annotater} from the GitHub source
remotes::install_github("luisDVA/annotater")
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
MonkmanMH / main_branch.md
Last active Oct 7, 2020
git command to rename branch of repo
View main_branch.md

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

But...you can do this as an Rmd with the git commands in a bash chunk

@MonkmanMH
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
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 https://github.com/rstudio/master-the-tidyverse by RStudio and https://github.com/cwickham/data-science-in-tidyverse-solutions. -->
```{r setup}
library(tidyverse)
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
@MonkmanMH
MonkmanMH / correlatedrandomvariables.r
Last active Oct 20, 2017
correlated random variables
View correlatedrandomvariables.r
## make it reproducible
set.seed(8675309)
## two normally distributed variables
X1 <- rnorm(100, mean = 0, sd = 1)
X2 <- rnorm(100, mean = 0, sd = 1)
View dummy_var.R
# quick example of mutate (in the dplyr R package) to create a dummy variable
# packages (from the tidyverse)
library(tibble)
library(dplyr)
# a little tibble with an ID number and a gender variable (5 Female, 3 Male, 2 Not Stated)
mydata <- tibble(id = 1:10, gender = c("F", "F", "F", "F", "F",
"M", "M", "M",
"NS", "NS"))
You can’t perform that action at this time.