Description Usage Arguments Value Examples
add_missing adds rows for unused combinations of factor levels.
The function takes as input a data.frame or tibble, the column names of grouping variables, and a named list of default values.
1 | add_missing(x, group_cols, defaults)
|
x |
A data.frame or tibble. |
group_cols |
Vector of the names of the grouping columns. |
defaults |
A named list of default values. |
A tibble
A tibble or data.frame, depending on the class of x.
1 2 3 4 5 | iris_sub <- dplyr::filter(iris, Species != "virginica")
iris_summary <- dplyr::group_by(iris_sub, Species)
iris_summary <- dplyr::summarise(iris_summary, N = dplyr::n())
iris_summary <- dplyr::ungroup(iris_summary)
add_missing(iris_summary, "Species", list(N = 0))
|
`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 3 x 2
Species N
<fct> <dbl>
1 setosa 50
2 versicolor 50
3 virginica 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.