Skip to content

Instantly share code, notes, and snippets.

Thanks to Hilary Parker for the easy breezy template!
https://gist.github.com/hilaryparker/046f55f5222b12692d74
#load packages
library(babynames)
library(dplyr)
library(ggplot2)
library(grid)
library(wesanderson)
@apreshill
apreshill / read-multiple-csv-files
Created March 18, 2016 14:50
Read multiple csv files into R
# stack overflow answer from Joran Ellis:
# http://stackoverflow.com/questions/5319839/read-multiple-csv-files-into-separate-data-frames
# If the path is different than your working directory
# you'll need to set full.names = TRUE to get the full
# paths.
my_files <- list.files("path/to/files")
# Further arguments to read.csv can be passed in ...
all_csv <- lapply(my_files,read.csv,...)
@apreshill
apreshill / ipak.R
Created March 25, 2016 04:42 — forked from stevenworthington/ipak.R
Install and load multiple R packages at once
# ipak function: install and load multiple R packages.
# check to see if packages are installed. Install them if they are not, then load them into the R session.
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
# convert all column names to snake case
# make all column names lower case
# replace all . with _
names2snake <- function(data){
require(stringr)
require(dplyr)
names(data) = names(data) %>%
tolower() %>%
str_replace_all(., "[.]", "_")
data
county sample state name exceedances
Mobile 20 al Dauphin Island Water & Sewer 1
Monroe 23 al Excel Water System 1
Washington 95 al Tate & Lyle Sucralose, Inc. Water System 1
Coosa 18.3 al Lake Mitchell Water, Incorporated 1
Juneau City and Borough 15.5 ak Thunder Mountain Mobile Park 1
Juneau City and Borough 31 ak Hecla Greens Creek Hawk Inlet 1
Ketchikan Gateway Borough 27.7 ak Boyer Towing 1
Ketchikan Gateway Borough 32.9 ak Thorne Bay, City Of 1
Ketchikan Gateway Borough 16.2 ak Clover Pass Christian School 2
@apreshill
apreshill / cdc_addm_all.csv
Last active April 1, 2016 17:30
Prevalence of ASD in the US from most recent 4 CDC ADDM surveys
site total n_asd prevalence_1000 data_source l95_1000 u95_1000 year_survey year_pub birth_cohort table for_line
Alabama 36566 174 4.8 ho 4.1 5.5 2008 2012 2000 2 1
Arizona 32601 507 15.6 eh 14.3 17 2008 2012 2000 2 1
Arkansas 4940 52 10.5 eh 8 13.8 2008 2012 2000 2 1
Colorado 7725 91 11.8 eh 9.6 14.5 2008 2012 2000 2 0
Colorado 29336 188 6.4 ho 5.6 7.4 2008 2012 2000 2 1
Florida 29366 211 7.2 ho 6.3 8.2 2008 2012 2000 2 1
Georgia 50427 601 11.9 eh 11 12.9 2008 2012 2000 2 1
Maryland 27022 336 12.4 eh 11.2 13.8 2008 2012 2000 2 1
Missouri 25668 357 13.9 ho 12.5 15.4 2008 2012 2000 2 1
@apreshill
apreshill / orly-owl-residuals
Last active July 12, 2020 21:57
Shows us why visualizing residuals from a model is important
library(broom)
library(ggplot2)
# read in the data
# others available here: http://www4.stat.ncsu.edu/~stefanski/NSF_Supported/Hidden_Images/stat_res_plots.html
owl <- read.table("http://www4.stat.ncsu.edu/~stefanski/NSF_Supported/Hidden_Images/orly_owl_files/orly_owl_Lin_4p_5_flat.txt",
header = FALSE)
# fit the linear model
fit <- lm(V1 ~ . - 1, data = owl)
tap 'homebrew/cask'
tap 'homebrew/cask-fonts'
tap 'homebrew/cask-versions'
tap 'homebrew/cask-drivers'
cask_args appdir: '/Applications'
# Version Control
brew 'git', args: ['with-persistent-https',
'with-curl',
# Create a GitHub PAT
# Hint: use the usethis package
# see: http://happygitwithr.com/github-pat.html#step-by-step
library(usethis)
browse_github_pat() # takes you to browser
# Add it to .Renviron
# Hint: use the usethis package
edit_r_environ() # makes the file if not yet made- needs blank line at end!
# now copy/paste long PAT with = sign
library(tidyverse)
msleep <- msleep %>%
select(name:order)
msleep
msleep %>%
add_count(vore) %>% # n = vores
count(vore, order, n) %>% # nn = unique orders per vore