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
.. |> | |
nest(data = ..) |> | |
mutate(data = pmap( | |
lst(data, min_date, max_date), | |
~with(list(...), mutate(data, glob_min_date = min_date)))) |
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
dbtbl |> filter(row_number() < .., .by=..) |
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
expand_grid( | |
pick_n = 1:3) |> | |
rowwise() |> | |
mutate(mtr = unlist(list(measure( | |
sam_vos, n_weeks=4, fn = \(x) sort(x)[pick_n])))) |> | |
# OR unnamed | |
mutate(mtr = unlist(list(apply_to_wur(lst(across(ev()))))) |> | |
ungroup() |> | |
pprint() | |
# more: https://dplyr.tidyverse.org/articles/rowwise.html#repeated-function-calls |
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
# you can use it in Power BI to build a table of insights that will help you not to miss important influencers | |
suppressWarnings(suppressPackageStartupMessages({ | |
library(tidyverse) | |
library(forcats) | |
library(ggplot2) | |
library(Hmisc)})) | |
custom_lump <- function(fct, min_size=nrow(tbl) / n_bins) { | |
kept_levels <- fct %>% | |
table() %>% |
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
tbl %>% mutate(res=pmap(., ~with(list(...), {any_col is available here! |
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
?dplyr::context | |
# gives us | |
cur_column() - current column name! | |
cur_<press tab> | |
n() | |
disp <- 10 | |
mtcars %>% mutate(disp = .data$disp * .env$disp) | |
mtcars %>% mutate(disp = disp * disp) | |
?.data |
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
group_in_func <- function(x, ...) { | |
x %>% | |
group_by(!!!(...)) %>% | |
summarise(sum(mpg)) | |
} | |
list(quos(any_name=cyl == 6)) %>% | |
map( | |
group_in_func, | |
x=head(select(as_tibble(mtcars), 1:2), 5) %>% print()) |
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
pivot_longer( | |
cols=-c(date, match_id), | |
names_to=c("side", ".value"), | |
names_sep='(?<=^[ha])_') | |
pivot_wider( | |
id_cols=c(date, h_team, a_team), | |
names_from=side, | |
names_glue = "{side}_{.value}", | |
values_from=-c(date, h_team, a_team, team, side)) |
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
# let's say we have a set of features and want to create a bunch of their interations | |
# Which should we use? I tried to answer this question thinking that | |
# correlation is a good measure of novelty and usefullness of the information | |
explore$interactions <- function(df) { | |
assert(ncol(df) == 2) | |
df %>% | |
# { print(explore$cor_tibble(.)); . } %>% | |
mutate(sum=.[[1]] + .[[2]]) %>% | |
mutate(dif=.[[1]] - .[[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
tbl %>% | |
rowwise() %>% | |
group_map(~{...}) | |
tbl %>% | |
mutate(i=1:n()) %>% | |
nest(data=-i) %>% | |
pluck('data') %>% | |
map(~{...}) |
NewerOlder