Description Usage Arguments Examples
Take a data frame grouped with [dplyr::group_by()) and summarise by
combinations of the grouping variables, e.g. by the first variable, by the
first two, the first three, etc. With method = "combination"
all
combinations will be summarised, e.g. a
, a
and b
, a
and c
, b
and
c
. With method = "individual"
each grouping variable will be used once,
e.g. by the first variable, by the second variable, the third variable, etc.
The output is a data frame with NA
in unused grouping variables.
Alternatively use bind = FALSE
to return a list of data frames, one per
combination of grouping variables.
1 2 |
.data |
A tbl. All main verbs are S3 generics and provide methods
for |
... |
Name-value pairs of summary functions. The name will be the
name of the variable in the result. The value should be an expression
that returns a single value like The arguments in |
bind |
Whether to combine all margins into one data frame. Default is
|
method |
One of
|
hierarchy |
Deprecated. The default |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | mtcars %>%
dplyr::group_by(cyl, gear, am) %>%
margins(mpg = mean(mpg, na.rm = TRUE),
hp = min(hp),
bind = FALSE,
method = "hierarchy")
mtcars %>%
dplyr::group_by(cyl, gear, am) %>%
margins(mpg = mean(mpg, na.rm = TRUE),
hp = min(hp),
bind = TRUE,
method = "hierarchy") %>%
print(n = Inf)
mtcars %>%
dplyr::group_by(cyl, gear, am) %>%
margins(mpg = mean(mpg, na.rm = TRUE),
hp = min(hp),
bind = FALSE,
method = "combination")
mtcars %>%
dplyr::group_by(cyl, gear, am) %>%
margins(mpg = mean(mpg, na.rm = TRUE),
hp = min(hp),
bind = FALSE,
method = "individual")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.