This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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,...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder