This file contains 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
pal <- c("#005595", # Medium Electric Blue | |
"#5E7F24", # Sap Green | |
"#D87E1A", # Ochre | |
"#007FAD", # Celadon Blue | |
"#A01C3F", # Deep Carmine | |
"#F2F2F2", # Anti-Flash White | |
"#949494", # Spanish Gray | |
"#606060", # Granite Gray | |
# Sequential Blue | |
"#6799BF", "#4779B1", "#005595", "#00406F", "#002B4A", |
This file contains 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
# US Census ACS 5-year API documentation: https://www.census.gov/data/developers/data-sets/acs-5year.html | |
# tidycensus documentation: https://walker-data.com/tidycensus/ | |
Sys.getenv("CENSUS_API_KEY") # load pre-installed Census API key | |
getACSbyZCTA <- function(lookup, table = NULL, variables = NULL, dataset = "acs5/profile", year = 2021) { | |
require(magrittr) | |
require(dplyr) | |
require(tidyr) | |
require(tidycensus) |
This file contains 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
search <- function(file, str) { | |
text <- readLines(file.path(path, file), warn = FALSE) | |
df <- data.frame(file = file, | |
line = 1:length(text), | |
regex = str, | |
result = grepl(str, text), | |
text) | |
df[df$result == TRUE, ] | |
} |
This file contains 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
# Reference: https://www.bls.gov/developers/api_r.htm | |
library(magrittr) | |
library(dplyr) | |
library(devtools) | |
install_github("mikeasilva/blsAPI") # https://github.com/mikeasilva/blsAPI | |
library(rjson) | |
library(blsAPI) | |
payload <- list("seriesid" = c("CUUR0000SA0L1E"), | |
"startyear" = 2016, |
This file contains 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
c(rgb( 26, 26, 26, maxColorValue = 255), | |
rgb( 51, 51, 51, maxColorValue = 255), | |
rgb( 77, 77, 77, maxColorValue = 255), | |
rgb(102, 102, 102, maxColorValue = 255), | |
rgb(127, 127, 127, maxColorValue = 255), | |
rgb(153, 153, 153, maxColorValue = 255), | |
rgb(179, 179, 179, maxColorValue = 255), | |
rgb(204, 204, 204, maxColorValue = 255), | |
rgb(230, 230, 230, maxColorValue = 255)) |
This file contains 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(magrittr) | |
library(dplyr) | |
c("Alice", | |
"Bob", | |
"Carol", | |
"Dave") %>% | |
unique() %>% | |
sample(1e6, replace = TRUE) %>% | |
data.frame(names = .) %>% |
This file contains 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(magrittr) | |
library(readr) | |
library(tidyr) | |
library(censusapi) | |
name <- "acs/acs5" # See https://api.census.gov/data.html for list of tables for the name argument for listCensusMetadata() | |
vintage <- 2012 | |
metadata <- | |
listCensusMetadata(name = name, vintage = vintage) %>% |
This file contains 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
# Ref: https://en.wikipedia.org/wiki/Birthday_problem | |
# Ref: https://www.scientificamerican.com/article/bring-science-home-probability-birthday-paradox/ | |
library(magrittr) | |
library(dplyr) | |
people <- 23 | |
simulations <- 1e5 | |
expand.grid(id = 1:people, | |
sim = 1:simulations) %>% | |
mutate(bday = sample(365, simulations * people, replace = TRUE)) %>% | |
group_by(sim) %>% |
This file contains 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(magrittr) | |
library(dplyr) | |
buildSample <- function(hosp, pop = 500, samp = 100) { | |
data.frame(hosp = hosp, | |
id = sample(pop, samp, replace = TRUE), | |
stringsAsFactors = FALSE) %>% | |
mutate(z = rnorm(nrow(.))) | |
} | |
df1 <- buildSample("A") | |
df2 <- buildSample("B") |
This file contains 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
to bcd:continue | |
start_mazegaze | |
end | |
to bcd:instructions | |
cs right 90 label "every_command_will_start_with_BCD:_or_will_be_a_random_series_of_letters. wait 275 cs right 90 label "Dont_be_confused_by_this._it's_for_programming_reasons. wait 275 cs right 90 label "the_computer_will_show_you_a_maze_for_several_seconds. wait 275 cs right 90 label "then_it_will_ask_you_how_to_solve_the_maze. wait 275 cs right 90 label "Solve_it_right_or_you'll_have_to_start_over. wait 275 cs right 90 label "type_BCD:continue | |
end | |
to bcd:start | |
cs bk 100 fd 160 pu fd 40 pd rt 90 fd 80 pu fd 40 pd fd 80 rt 90 fd 200 rt 90 fd 200 rt 90 fd 160 rt 90 fd 40 bk 40 rt 90 fd 80 lt 90 fd 40 lt 90 fd 80 lt 90 fd 40 rt 90 pu fd 40 rt 90 fd 80 rt 90 pd fd 160 rt 90 fd 40 pu bk 80 rt 90 pd fd 120 rt 90 fd 40 rt 90 fd 120 rt 90 fd 40 rt 90 fd 120 lt 90 fd 40 rt 90 fd 40 pu fd 40 rt 90 fd 10 pd label "s wait 375 cs |
NewerOlder