Created
April 9, 2020 10:23
-
-
Save garethclews/7740b2c966610c5712abe9c50422a7a1 to your computer and use it in GitHub Desktop.
Ash help
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
weighted_count <- function(data, weights, ...) { | |
group_ <- enquos(...) | |
data %>% | |
group_by(!!!group_) %>% | |
summarise(amount = sum(.data[[weights]]), n = n()) | |
} | |
iris %>% weighted_count("Petal.Length", Species) | |
## A tibble: 3 x 3 | |
# Species amount n | |
# <fct> <dbl> <int> | |
# 1 setosa 73.1 50 | |
# 2 versicolor 213 50 | |
# 3 virginica 278. 50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment