Description Usage Arguments Value See Also Examples
Alter a function to operate over groups and all possible subsets of groupings, including no grouping.
1 | with_margins(FUN, all.name = "(All)")
|
FUN |
the function to wrap. |
all.name |
the string to use to represent that a variable was marginalized over. |
Returns a function which alters the given FUN
to be run for
each possible subset of groupings and row bind
the results together.
For understanding marginals:
Marginal distributions on Wikipedia.
Marginal frequency on statistics dictionary.
1 2 3 4 5 | library(dplyr)
x <- c( 'a', 'b', 'c')
y <- c( 'd', 'e', 'f')
data <- group_by(mutate(expand.grid( x = x, y = y, .rep = 1:10), v = rnorm(90)), x, y)
with_margins(summarise)(data, N=n(), sum=sum(v))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.