R

US CO2 emissions by source

library(pacman) p_load(tidyverse, scales, ggthemes, RColorBrewer, plotly) energy_cons <- read_csv("https://www.eia.gov/totalenergy/data/browser/csv.php?tbl=T12.01") energy_cons %>% glimpse ## Observations: 8,288 ## Variables: 6 ## $ MSN <chr> "CKTCEUS", "CKTCEUS", "CKTCEUS", "CKTCEUS", "CKTC… ## $ YYYYMM <int> 197301, 197302, 197303, 197304, 197305, 197306, 1… ## $ Value <dbl> 108.289, 97.698, 97.366, 93.084, 94.346, 97.757, … ## $ Column_Order <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.

Use pmap from R package purrr to combine spreadsheets

library('pacman') p_load(tidyverse, readxl, purrr) # download xlsx files from moodle put in List file <- list.files(pattern = "*.xlsx") # columns (course, group) to add to each spreadsheet course <- c("fa-18-IntAcctA", "fa-18-IntAcctA", "fa-18-AdvAcct") group <- c("12PM", "2PM", "4PM") files_in <- function(file, course, group){ file %>% read_xlsx() %>% select(firstname = First name, lastname = Last name, username = ID number, email = Email address) %>% mutate(course1 = course, group1 = group) %>% select(firstname, lastname, username, course1, group1, email) } l <- list(file, course, group ) pmap_dfr(l, files_in) %>% write_csv("enroll-fa18.