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

Arguments

data

a data frame ... one or more variable names, unquoted label a character string specifying the name of the combined category, default is "All".

...

a list of names of variables to marginalize

label

category name for added marginal observations

Examples

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

[Package Hmisc version 3.14-4 Index]