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(tidyverse) | |
library(lubridate) | |
dat <- tribble(~id, ~start, ~end, | |
0102, "2018-01-02", "2018-01-07", | |
2190, "2018-01-01", "2018-03-06", | |
2432, "2018-01-03", "2018-05-07", | |
0121, "2018-01-03", "2018-02-04", | |
0121, "2018-01-02", "2018-01-15", | |
) |
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
# Adaption of w3schools overlay page | |
# https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_overlay_text | |
library(shiny) | |
library(shinyjs) | |
# Overlay js function | |
jsCode <- " | |
shinyjs.overlay_on = function() { |
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
l1 <- structure(list(x = 1), attr = 1) | |
l2 <- structure(list(y = 2), attr = 2) | |
d <- function(...) { | |
dots <- match.call(expand.dots = FALSE)$... | |
attr_ls <- lapply(dots, function(x) attributes(get(as.character(x)))) | |
attr_ls <- lapply(purrr::transpose(attr_ls), unlist) | |
out <- c(...) |
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(tidyverse) | |
contains_comma <- function(x) { | |
if (is.character(x) || is.factor(x)) { | |
any(str_detect(x, ",")) | |
} else {FALSE} | |
} | |
gss_cat %>% | |
select(where(contains_comma)) |
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(dplyr) | |
set.seed(123) | |
dat <- tibble(main_grp = rep(c("a", "b"), each = 4), | |
sub_grp = rep(c("x", "y"), 4), | |
value = rnorm(8)) | |
dat %>% | |
bind_rows(., mutate(dat, sub_grp = "subtotal")) %>% |
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
seq_sum <- function(from, to, .sum, exact = FALSE) { | |
a <- from + to | |
m <- a/2 | |
d <- .sum - a | |
if (exact && (d %% m !=0)) { | |
stop("sequence didn't converge.") | |
} | |
i <- (d / m) + 2 |
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(dplyr) | |
# Add Total Mean for numeric variables | |
iris %>% | |
add_row( | |
summarise(., | |
Species = "Total mean", | |
across(where(is.numeric), mean)) | |
) %>% | |
tail() # for printing |
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
# this reduce() and done() combo mimics a while loop | |
# coming from this tweet | |
# https://twitter.com/norimitsunishi1/status/1554353454360932353?s=21&t=lopKMBKt-SKQfOlrM5B_Iw | |
# of course this is NOT a good solution, since the input to reduce has a limited length, ... | |
# ... whereas the while loop will just go on forever until it breaks. | |
library(purrr) | |
f <- function(char, char2) { | |
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(tidyverse) | |
library(gapminder) | |
# lists of independent variables | |
indep_var_country <- list( | |
"gdp_only" = "gdpPercap", | |
"gdp_and_pop" = c("pop", "gdpPercap") | |
) | |
indep_var_continent <- append( |
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(tidyverse) | |
set.seed(123) | |
# some random dataa | |
my_dat <- tibble( | |
y = rbinom(300, 1, 0.5), # outcome 1 | |
z = rbinom(300, 1, 0.5), # outcome 2 | |
t = rbinom(300, 1, 0.5), # outcome 3 | |
indep_var = runif(300), # this is our independet variable |
OlderNewer