Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
thoughtfulbloke / NZtrade.R
Created September 26, 2025 02:52
Processing NZ Trade data
library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(lubridate)
library(RcppRoll)
source("~/theme.R")
datafiles <- list.files(pattern="csv$")
# remove the older provisional files that I have the directory
library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggthemes)
source("~/theme.R")
WVS <- read_csv("~/Downloads/WVS_Cross-National_Wave_7_csv_v6_0.csv")
shorter <- WVS |>
filter(B_COUNTRY_ALPHA %in% c("DEU", "RUS","IND", "USA", "KOR", "NZL")) |>
select(B_COUNTRY_ALPHA, Q7:Q17)
library(ggplot2)
library(maps)
library(dplyr)
# while the position data in the maps package
# is very basic, that makes it simple to transform
nz_map <- map_data("nz")
nz_anti <- nz_map %>%
mutate(
@thoughtfulbloke
thoughtfulbloke / Excel_arrangement
Created February 10, 2025 20:34
NZ covid data organised for excel graphing
"Week_Ending","Border_Cases","Community_Cases","Deaths"
2020-02-23,0,0,0
2020-03-01,1,0,0
2020-03-08,4,2,0
2020-03-15,3,0,0
2020-03-22,56,22,0
2020-03-29,273,180,1
2020-04-05,160,350,0
2020-04-12,52,232,4
2020-04-19,16,81,7
@thoughtfulbloke
thoughtfulbloke / gist:7aeb5174d6ccc6e09ae170d4de0f16e9
Created January 18, 2025 03:25
proof of concept of batch add info from EXIF as text on photos using magick and exiftoolr in R
library(magick)
library(exiftoolr)
# Hard-coded folder path
folder <- "~/Desktop/photos"
# Function to process images
process_images <- function(folder) {
# Create the "texted" subfolder if it doesn't exist
texted_folder <- file.path(folder, "texted")
library(shiny)
library(magick)
ui <- fluidPage(
titlePanel("Image Upload and Text Overlay"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose an Image File",
accept = c('image/png', 'image/jpeg')),
library(dplyr)
asLines <- readLines("d12.txt")
height <- length(asLines)
width <- nchar(asLines[1])
chars <- strsplit(paste(asLines, collapse = ""), "")[[1]]
aCropMatrix <- matrix(chars, nrow = height, byrow = TRUE)
aFieldMatrix <- matrix(1:length(chars), nrow = height, byrow = TRUE)
priorFieldMatrix <- matrix(rep(1, length(chars)), nrow = height, byrow = TRUE)
while (!identical(priorFieldMatrix, aFieldMatrix)) {
@thoughtfulbloke
thoughtfulbloke / Advent_of_code_2024_day07_part2.R
Created December 7, 2024 21:20
My very tidy solution to day7 in the advent of code
library(gtools)
library(stringr)
library(dplyr)
library(tidyr)
d7 <- readLines("day07.txt")
#assumes you kept the resut of part1 to save work
d7p1 <- as.numeric(readLines("d7p1result.txt"))
p2data <- d7[d7p1 == 0]
p2sums <- as.numeric(gsub(":.*","",p2data))
p2input <- gsub(".*: ","",p2data)
@thoughtfulbloke
thoughtfulbloke / gist:4c87c97db569f821eb134eb876e79c99
Created November 24, 2024 18:14
Day 25 2024 #30daymapchallenge code
library(rvest)
library(dplyr)
library(RcppRoll)
library(tidygeocoder)
library(maps)
library(mapdata)
library(ggplot2)
library(viridis)
library(patchwork)
library(ggtext)
@thoughtfulbloke
thoughtfulbloke / MortalityRates.csv
Last active December 15, 2024 01:13
NZ Weekly Mortality Rates by Age(<30,30-59,60-79,80+). Date of Death not Registration. Weekly population interpolated from as at Quarter end. source StatsNZ and DIA (via file emailed to me)
Period Ages RawDeaths InterpPop DeathRateMillion
2000-01-09 30 to 59 74 1569863.62637363 47.1378524585218
2000-01-09 60 to 79 189 495217.472527473 381.650508079589
2000-01-09 80 and over 194 104575.054945055 1855.12692392971
2000-01-09 Under 30 27 1681940.65934066 16.0528850111658
2000-01-16 30 to 59 64 1570169.78021978 40.7599234211741
2000-01-16 60 to 79 196 495324.395604396 395.700275898667
2000-01-16 80 and over 226 104711.208791209 2158.31717166629
2000-01-16 Under 30 14 1681754.50549451 8.32463950847774
2000-01-23 30 to 59 73 1570475.93406593 46.4827243872527