Learn R Programming

fifer (version 1.1)

demographics: Summarize a Data Set (Demographics)

Description

Creates a summary table of a data set in a matrix object for pretty printing via xtable.

Usage

demographics(formula, data, latex = TRUE, na.action = na.pass, ...)

Arguments

formula
A formula, with the left-hand side being empty or a group variable to summarize by. The right-hand side should include variables to summarize by; they should be either continuous variables or factors/characters.
data
A data.frame where the variables in formula come from; if not specified, variables are looked for in the parent environment.
latex
A logical variable that determines whether the resulting output will be part of a LaTeX document. Defaults to TRUE.
na.action
A function to handle missing data. See na.pass.
...
Additional arguments passed to SummarizeVar, such as decimalFactor, decimalContinuous, ContinuousSummaryFunction, and FactorSummaryFunction.

Value

A matrix to be used with xtable, which in turn should be used in print.xtable.

Details

This is generally used to create demographics table and used with the package xtable to print. To get proper names to display, a data.frame should be constructed such that the variable names are what the users want to be displayed. For factor variables, the user should make use of the levels and labels arguments in factor.

Examples

Run this code
set.seed(1)
n <- 50
df <- data.frame(trt=sample(0:1, 2*n, replace=TRUE), x1=runif(2*n), x2=rnorm(2*n), 
   x3=sample(c("a", "b", "c"), 2*n, replace=TRUE))
demographics(~x1+x2+x3, data=df)
demographics(trt~x1+x2+x3, data=df)
demographics(~., data=df)
demographics(trt~., data=df, decimalFactor=2)
## Not run: print(xtable(Summarize(trt~., data=df)), sanitize.text.function=identity)

Run the code above in your browser using DataLab