Learn R Programming

tidymargins (version 0.1.0)

with_margins: Operate over margins

Description

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

Usage

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

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab