with_margins: Operate over margins

Description Usage Arguments Value See Also Examples

View source: R/margins.R

Description

Alter a function to operate over groups and all possible subsets of groupings, including no grouping.

Usage

1
with_margins(FUN, all.name = "(All)")

Arguments

FUN

the function to wrap.

all.name

the string to use to represent that a variable was marginalized over.

Value

Returns a function which alters the given FUN to be run for each possible subset of groupings and row bind the results together.

See Also

For understanding marginals:

Examples

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))

tidymargins documentation built on July 23, 2019, 5:04 p.m.