addMarginal

0th

Percentile

Add Marginal Observations

Given a data frame and the names of variable, doubles the data frame for each variable with a new category "All" (or optionally "Combined"). A new variable .marginal. is added to the resulting data frame, with value "" if the observation is an original one, and with value equal to the names of the variable being marginalized (separated by commas) otherwise.

Keywords
manip, utilities
Usage
addMarginal(data, ..., label = "All", margloc=c('last', 'first'))
Arguments
data
a data frame
...
a list of names of variables to marginalize
label
category name for added marginal observations
margloc
location for marginal category within factor variable specifying categories. Set to "first" to override the default - to put a category with value label as the first category.
Aliases
  • addMarginal
Examples
d <- expand.grid(sex=c('female', 'male'), country=c('US', 'Romania'),
                 reps=1:2)
addMarginal(d, sex, country)
Documentation reproduced from package Hmisc, version 4.0-2, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.