add_margins

0th

Percentile

Add margins to a data frame.

Rownames are silently stripped. All margining variables will be converted to factors.

Usage
add_margins(df, vars, margins = TRUE)
Arguments
df

input data frame

vars

a list of character vectors giving the variables in each dimension

margins

a character vector of variable names to compute margins for. TRUE will compute all possible margins.

Aliases
  • add_margins
Documentation reproduced from package reshape2, version 1.4.3, License: MIT + file LICENSE

Community examples

colloboh@gmail.com at Aug 28, 2020 reshape2 v1.4.3

#1 outputs average mpg based on cylinder mtcars %>% group_by(cyl) %>% summarize(AVG_MPG = mean(mpg)) #2 output same as above but adds an (all) row which has the average mpg for all cars in data frame mtcars %>% reshape2::add_margins("cyl") %>% group_by(cyl) %>% summarize(AVG_MPG = mean(mpg))