Skip to content

Instantly share code, notes, and snippets.

View MokeEire's full-sized avatar

Mark MokeEire

View GitHub Profile
@MokeEire
MokeEire / trip_plot_dist.R
Created October 30, 2021 04:13
Visualizing Google Maps Trip Durations (distributions)
library(tidyverse)
library(lubridate)
library(ggdist)
library(distributional)
tibble::tribble(~departure_time, ~duration_min, ~duration_max,
"9:00am", lubridate::dminutes(65), dminutes(100),
#"9:15am", lubridate::dminutes(70), dminutes(100),
"9:30am", lubridate::dminutes(70), dminutes(110),
#"9:45am", lubridate::dminutes(70), dminutes(110),
@MokeEire
MokeEire / trip_plot.R
Created October 30, 2021 04:01
Visualizing Google Maps Trip Durations
tibble::tribble(~departure_time, ~duration_min, ~duration_max,
"9:00am", lubridate::dminutes(65), dminutes(100),
#"9:15am", lubridate::dminutes(70), dminutes(100),
"9:30am", lubridate::dminutes(70), dminutes(110),
#"9:45am", lubridate::dminutes(70), dminutes(110),
"10:00am", lubridate::dminutes(75), dminutes(130),
#"10:15am", lubridate::dminutes(75), dminutes(130),
"10:30am", lubridate::dminutes(80), dminutes(130),
#"10:45am", lubridate::dminutes(80), dminutes(140),
"11:00am", lubridate::dminutes(80), dminutes(140),
@MokeEire
MokeEire / build_codebook.R
Last active December 15, 2020 19:30
Build a codebook from a dataframe
library(tidyverse)
library(lubridate)
# The function below was written primarily with the aim of producing a codebook which can be exported to Excel.
# If you are trying to get a quick understanding of your data, str(), glimpse(), or summary() will all likely better serve you
# If you use this and make any improvements, please let me know.
# There's lots of room for this to be improved.
# - Check for presence of each data type, and perform processing accordingly
# - Check if the remaining df is empty after summarising each data type
# I wrote it without any safeguards because I know what I use it for but it could definitely use some more careful argument checking
@MokeEire
MokeEire / relabel_multiple_cols.R
Last active July 14, 2022 05:31
Use `cols_label` to relabel multiple columns with the `gt` package
library(tidyverse)
library(gt)
# Read in data
# Using LA Budget data: https://controllerdata.lacity.org/Budget/City-Budget-and-Expenditures/uyzw-yi8n
la_budget_raw = read_csv("https://controllerdata.lacity.org/api/views/uyzw-yi8n/rows.csv?accessType=DOWNLOAD")
## OPTIONAL ##
# cleaner column names
library(janitor)