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(rlang) | |
set.seed(123) | |
df <- tibble(id = rep(c(1:2), 10), | |
grade = sample(c("A", "B", "C"), 20, replace = TRUE)) | |
df %>% | |
group_by(id) %>% | |
summarise( |
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(janitor) | |
library(EnvStats) | |
library(infer) | |
library(ggthemes) | |
set.seed(123) | |
old = theme_set(theme_minimal(base_family = "Noto Sans CJK SC") + | |
theme(legend.position = "top")) | |
# DID ---- |
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(feather) | |
library(dplyr) | |
library(purrr) | |
library(furrr) | |
library(uaparserjs) | |
raw <- feather::read_feather("raw.feather") %>% | |
`[[`('ua') %>% | |
purrr::discard(is.na) %>% | |
unique() |
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(ggthemes) | |
library(lubridate) | |
library(gganimate) | |
# ggplot theme | |
old <- theme_set( | |
theme_minimal() + | |
theme( | |
text = element_text(family = 'Menlo'), |
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
set.seed(1234) | |
vec = c(13.1, 7.5, 4.4, 10.0, 7.8, 3.4, 3.5) / 100 | |
rb = EnvStats::ebeta(vec) | |
alpha = rb$parameters['shape1'] | |
beta = rb$parameters['shape2'] | |
x <- rbeta(1000, shape1 = alpha, shape2 = beta) | |
hist( | |
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
cuts = 0.8 # cutoff level | |
maxN = 100 # number of trials | |
run_game <- function(vec, cutoff, N) { | |
# browser() | |
if (length(vec) > N) { | |
return(vec) | |
} | |
pass = ifelse(mean(vec) >= cutoff, 0, 1) | |
vec = c(vec, pass) |
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
## the game goes like this, | |
## head +1 point and tail -1 point | |
## we flip 3 coins and count the score | |
## is there a correlation between them? | |
library(tidyverse) | |
library(ggthemes) | |
set.seed(1234) | |
coins = 4 |
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) | |
# some dummy data | |
df <- read_csv("dummy.csv") | |
# loess fitting via ggplot2 | |
df %>% | |
mutate(batch = factor(batch, | |
ordered = TRUE, | |
levels = paste0("X00", 1:12))) %>% |
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
Sub MergeSimilarCells() | |
Application.DisplayAlerts = False | |
Application.ScreenUpdating = False | |
'Specify column here | |
Set myRange = Range("B2:B223") | |
CheckAgain: | |
For Each cell In myRange | |
If cell.Value = cell.Offset(1, 0).Value And Not IsEmpty(cell) Then | |
Range(cell, cell.Offset(1, 0)).Merge |
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(furrr) | |
# for parallel computing | |
future::plan(future::multiprocess) | |
options(future.globals.maxSize = 900*1024^2) | |
# remove significant jump in May 2020 | |
max_date <- as.Date("2020-03-02") | |
# sequence of backtest | |
date_seq <- purrr::map(0:36, ~ max_date - months(1 * .x)) |