addMarginal {Hmisc} | R Documentation

## Add Marginal Observations

### Description

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.

### 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.

### Examples

    d <- expand.grid(sex=c('female', 'male'), country=c('US', 'Romania'),
                     reps=1:2)
    addMarginal(d, sex, country)

[Package Hmisc version 3.17-4 Index]