Skip to content

Instantly share code, notes, and snippets.

View mattjcamp's full-sized avatar
😍
Analyzing

Matt Campbell mattjcamp

😍
Analyzing
View GitHub Profile
@mattjcamp
mattjcamp / read_in_xml.R
Last active September 8, 2024 17:17
R RStudio XML Process Apple Healthkit
options(stringsAsFactors = FALSE)
library(tidyverse)
library(xml2)
library(lubridate)
# Your codebase is well-structured and clear. It effectively uses the `tidyverse` and `xml2` libraries to process and manipulate the XML data. The comments are helpful in understanding the steps involved in exporting and processing the Apple Health data. Overall, it looks like a solid foundation for further development and analysis.
# NOTE: double check that week and past_week have the right days in them
#
# Process the XML file obtained from the Apple Health App. To get this file
@mattjcamp
mattjcamp / Scarface, 1983
Last active October 27, 2023 16:16
R Essentials
# Control Statements
# Load the tidyverse package
library(dplyr)
# Create a sample data frame
data <- data.frame(
day = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
)
@mattjcamp
mattjcamp / Start Database
Last active October 17, 2023 18:48
Postgres Admin
pg_ctl -D /Users/campbellm/postgres/bccc -l logfile start
@mattjcamp
mattjcamp / basic.sql
Last active October 17, 2023 17:02
SQL Essentials
-- SELECT WITH GROUP BY AND JOIN
SELECT
C.country,
C.team,
SUM(M.goals)
FROM countries AS C
LEFT JOIN matches AS M
ON C.team_id = M.home_team_id
WHERE M.year > 1990
GROUP BY
@mattjcamp
mattjcamp / append.sql
Last active October 13, 2023 12:38
SQL Tables
INSERT INTO TargetTable
SELECT * FROM SourceTable;
INSERT INTO Orders (CustomerID, OrderDate, TotalAmount)
VALUES
(1, '2023-09-19', 100.50),
(2, '2023-09-18', 75.25),
(3, '2023-09-17', 150.00);
@mattjcamp
mattjcamp / kmeans_r.R
Last active September 22, 2023 12:46
RStudio Kmeans
library(tidyverse)
library(lubridate)
library(lutz)
library(maptools)
datadir <- sprintf("%s/%s", here::here(), "04.findings.1/data")
load(file = sprintf("%s/%s", datadir, "nuforc_reports.rdata"))
# CLEAN AND CATEGORIZE
@mattjcamp
mattjcamp / column.r
Last active September 22, 2023 13:46
RStudio ggplot2
library(ggplot2)
wiche_us <- lookup_wiche(year = 2006, gender = c("f", "m"))
ggplot(data = wiche_us, aes(gender, n)) +
geom_bar(stat = "identity", position = "dodge")
wiche_us <- lookup_wiche(
year = 2006,
race = c("white", "asian", "hispanic", "native", "black")
)
@mattjcamp
mattjcamp / Edit_Distance.r
Last active September 22, 2023 12:57
R RStudio Fuzzy String Distance (adist, agrep, Levenshtein)
# stringdist
m <- stringdist(d$last_name_s, d$last_name_d, method = "lv")
# adist, provides matrix of every combo
s <- data.frame(list(person = c("ABCDEFG",
"ABCDEFG",
"ABCDEFG",
@mattjcamp
mattjcamp / df_change_all.r
Created November 15, 2016 17:28
R RStudio Change all cells in data frame to a value
df[is.na(df)] <- "*"
@mattjcamp
mattjcamp / grant_access.sql
Last active December 7, 2023 17:54
T-SQL Admin
GRANT SELECT ON DATABASE.TABLE TO user_name;
USE WorkdayStudent;
GRANT UPDATE, INSERT, DELETE TO campbellma;