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(rlang) | |
library(tidyverse) | |
split_ <- function(data, ..., .drop = TRUE) { | |
vars <- ensyms(...) | |
vars <- map(vars, function(x) eval(x, data)) | |
split(data, vars, drop = .drop) | |
} | |
mtcars %>% split_(cyl) |
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
# https://stackoverflow.com/questions/49880268/ggplot-how-to-remove-the-outliers-from-multiple-boxplots?noredirect=1#49880268 | |
library(tidyverse) | |
data(iris) | |
iris_long <- gather(iris, "key", "val", -Species) | |
# with the outliers | |
ggplot(iris_long, aes(Species, val)) + | |
geom_boxplot() + |
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(sf) | |
library(magrittr) | |
library(tidyverse) | |
gtfs_routes_sf <- function(gtfs) { | |
## gather key-values first ---- | |
# trips_df has route_id:shape_id | |
shape_key <- gtfs$trips_df %>% |
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
function export_gcal_to_gsheet(){ | |
// fill with your details | |
var mycal = "you@email.com"; | |
var cal = CalendarApp.getCalendarById("email.com@hakjshfkhflsafkshfklaj@group.calendar.google.com"); | |
// interval of interest | |
var events = cal.getEvents(new Date("August 1, 2018 00:00:00 CST"), new Date("August 31, 2018 23:59:59 CST")); | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
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
# https://en.wikipedia.org/wiki/Fizz_buzz | |
values <- 1:15 | |
rules <- c("fizz" = 3, "buzz" = 5) | |
container <- rep("", length.out = length(values)) | |
for (name in names(rules)) { | |
rule_idx <- values %% rules[name] == 0 |
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(shiny) | |
library(sf) | |
library(leaflet) | |
nc <- st_read(system.file("shape/nc.shp", package="sf")) | |
ui <- fluidPage( | |
titlePanel("inputMap in Shiny"), | |
sidebarLayout( | |
sidebarPanel( |
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
#' --- | |
#' title: The best title | |
#' author: You | |
#' date: 2019-12-25 | |
#' --- | |
library(magrittr) | |
library(tidyverse) | |
# Import ------------------------------------------------------------------ |
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(scales) | |
library(magrittr) | |
library(tidyverse) | |
theme_set( | |
ggthemes::theme_fivethirtyeight(base_size = 10) + | |
theme(legend.position = "right", | |
legend.direction = "vertical", | |
axis.title = element_text()) | |
) |
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
con <- file("test.log", "at") | |
sink(con, append=T, type = "message") | |
con <- file("test_sleep100.log", "at") | |
sink(con, append=T, type = "message") | |
library(purrr) | |
map(1:100, | |
possibly(function(x) { |
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
#' --- | |
#' title: Code snippet for demo and graphic in Probability-Proportional-To-Size-Sampling blogpost | |
#' author: nathancday--at-Github-- | |
#' date: 2022-10-24 | |
#' --- | |
# Libs -------------------------------------------------------------------- | |
library(cowplot) | |
library(tidyverse) |
OlderNewer