Created
December 8, 2020 18:30
-
-
Save MarcinKosinski/565de05f427d407fa410936905f5c9b0 to your computer and use it in GitHub Desktop.
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
# what it was | |
{if({my_stat} == "avg") {dplyr::summarise(., stat = mean(var_agg, na.rm = TRUE)) %>% | |
dplyr::pull(stat) %>% formattable::comma(label_digits)} | |
else if({my_stat} == "max") {dplyr::summarise(., stat = max(var_agg, na.rm = TRUE)) %>% | |
dplyr::pull(stat) %>% formattable::comma(label_digits)} | |
else if({my_stat} == "min") {dplyr::summarise(., stat = min(var_agg, na.rm = TRUE)) | |
# what it can be | |
possible values of my_stat are renamed to so that `avg` is now `mean` | |
fun <- get(my_stat, envir = .GlobalEnv) | |
{dplyr::summarise(., stat = fun(var_agg, na.rm = TRUE)) %>% | |
dplyr::pull(stat) %>% formattable::comma(label_digits)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment