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
# batch edit column names based on a particular phrase | |
# store data in global environment, modify | |
mpg <- ggplot2::mpg | |
colnames(mpg) <- paste("depression", colnames(mpg), sep = "_") | |
# as a function | |
rename_by_phrase <- function(.data, pattern, replacement){ | |
# modify variable names based on input |
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
# find where to locate Anchorage, AK using the albersusa package | |
# dependencies | |
library(albersusa) # composite projection | |
library(dplyr) # data wrangling | |
library(ggplot2) # mapping | |
library(mapview) # preview | |
library(sf) # spatial data | |
# load composite map |
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
--- | |
title: "SOC 1120-01" | |
subtitle: "Fall 2019 Attendance" | |
author: "Christopher Prener, Ph.D." | |
institute: "Saint Louis University" | |
date: "2019/08/19 (updated: `r Sys.Date()`)" | |
output: | |
xaringan::moon_reader: | |
lib_dir: libs | |
nature: |
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
# dependencies | |
library(dplyr) | |
library(googledrive) | |
library(lubridate) | |
library(readr) | |
library(stringr) | |
# download form data | |
forms <- drive_find(pattern = "FA19-01") |
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
# Bivariate Choropleth Map | |
## this is based on Timo Grossenbacher and Angelo Zehr's tutorial - | |
## https://timogrossenbacher.ch/2019/04/bivariate-maps-with-ggplot2-and-sf/ | |
# dependencies | |
library(dplyr) # data wrangling | |
library(ggplot2) # plotting | |
library(purrr) # iteration | |
library(tidyr) # data wrangling |
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
# Parse Census Bureau address range data | |
# Problem: | |
# We need a way to match incidents (that have address-level data) to the blockface they occur on. | |
# By blockface, I mean the houses on either side of a street between two cross streets (i.e. | |
# the 100-block of Main Street between 1st and 2nd Avenues). | |
# | |
# Typically, census block and city block shapefiles do not represent a blockface. Instead, | |
# they have parts of up to four different streets, typically representing half of a blockface | |
# for each of the included streets. So a block bounded by Main Street on the south, 1st Avenue |
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
# These two functions address a common problem in my work - files named "monthYYYY.CSV.html" - | |
# e.g. "August2018.CSV.html". The prep_dir() function creates a vector of filenames in a given directory | |
# and then iterates over each using purrr::map(). The map() function calls our second function, edit_filename(). | |
# For each time it is called, edit_filename() uses the magic of stringr and fs (okay, it isn't really magic) | |
# to rename the file appropriately. | |
# dependencies: | |
# install.packages(c("fs", "magrittr", "purrr", "stringr")) | |
# include in script: |
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
# dependencies | |
library(dplyr) # data wrangling | |
library(classInt) # calculate breaks | |
library(leaflet) # leaflet maps | |
library(sf) # spatial data tools | |
library(stringr) # work with strings | |
# load data and re-project to WGS 1984 | |
st_read("STL_DEMOS_Nhoods.shp", stringsAsFactors = FALSE) %>% | |
st_transform(crs = 4326) -> popChange |
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
# Workflow for Creating Multiple Choice Exams | |
# This process creates a pseudo-random sample of correct answers, and then generates | |
# an exam based on a specified number of questions assigned to different sections of | |
# the course. | |
# Install Dependencies | |
# install.packages(c("dplyr", "purrr", "readr", "rlang")) | |
# Create |
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
library(dplyr) | |
library(stringr) | |
# create test data | |
orders <- data.frame( | |
id = c(1,2,3,4), | |
items = c("Apples and Turkey", "Bacon and Crackers", "Bananas and Juice", "Pecan Pie and Ice Cream"), | |
stringsAsFactors = FALSE | |
) |
NewerOlder