Skip to content

Instantly share code, notes, and snippets.

# 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
@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)
}
@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,...)
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)