Skip to content

Instantly share code, notes, and snippets.

@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 / 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)
``` r
library(tidyverse)
iris %>%
count(Species)
#> # A tibble: 3 x 2
#> Species n
#> <fct> <int>
#> 1 setosa 50
#> 2 versicolor 50
``` r
library(tidyverse)
#> Warning: package 'forcats' was built under R version 3.5.2
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
library(tidyverse)
set.seed(1000)
asdpop_base <- tibble::tibble(
time1 = sample(1:100, 100, replace = F),
time2 = time1) %>%
tidyr::gather(x, y, time1:time2, factor_key = TRUE)
asdpop <- asdpop_base %>%
mutate(services = as.factor(case_when(
x == "time1" & y <= 30 ~ 1,

Keybase proof

I hereby claim:

  • I am apreshill on github.
  • I am alisonhill (https://keybase.io/alisonhill) on keybase.
  • I have a public key ASCucGQ8iaHYozuOw_4ZGI0JRFMRU-hq2paVGj_nlW35eQo

To claim this, I am signing this object:

library(tidyverse)
msleep <- msleep %>%
select(name:order)
msleep
msleep %>%
add_count(vore) %>% # n = vores
count(vore, order, n) %>% # nn = unique orders per vore
# 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
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',
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)