Skip to content

Instantly share code, notes, and snippets.

View MonkmanMH's full-sized avatar
🎯
Multi-tasking

Martin Monkman MonkmanMH

🎯
Multi-tasking
View GitHub Profile
@MonkmanMH
MonkmanMH / rename_master_to_main.Rmd
Created October 7, 2020 14:24
Rename GitHub repos
---
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/
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))
@MonkmanMH
MonkmanMH / ungroup_example.Rmd
Last active February 12, 2021 01:45
dplyr's ungroup function
# {dplyr}'s `ungroup()` function
```{r}
# packages
library(gapminder)
library(dplyr)
```
In this example, we calculate the difference in a country's life expectancy from the continent's mean life expectancy
- for example, the difference between life expectancy in Canada and the mean life expectancy of countries in the Americas
@MonkmanMH
MonkmanMH / separate_lat_lon.R
Created October 22, 2021 03:00
use `separate()` function from {tidyr} to split a variable
# OBJECTIVE:
# * latitude and longitude stored with degrees with degree symbol and minutes with decimal
# * separate into two columns for each, with degrees and minutes separated
# step 1 - create a test tibble called "geo_loc"
geo_loc <- tribble( ~ latitude, ~ longitude,
"48º 4.206", "124º 45.553",
"46º 59.4942", "124º 12.6362")
# ---
# step 2 - split into degrees and minutes columns
@MonkmanMH
MonkmanMH / breaks_ts_min_max.R
Last active September 29, 2022 17:01
Y axis breaks at min & max value {ggplot2}
# modified from / inspired by @GShotwell
# gist: https://gist.github.com/GShotwell/b19ef520b6d56f61a830fabb3454965b
df <- tibble(
value = rnorm(100, 50, 10),
date = seq.Date(from = ymd("2022-01-01"),
ymd("2022-04-10"),
by = "day"))