tableNominal {reporttools}R Documentation

Display descriptive statistics for nominal variables

Description

Many data analyses start with a display of descriptive statistics of important variables. This function takes a data frame of nominal variables and possible grouping (such as e.g. treatment), weighting, and subset variables and provides a LaTeX table of descriptive statistics separately per group and jointly for all observations, per variable.

Usage

tableNominal(vars, weights = NA, subset = NA, 
    group = NA, miss.cat = NA, print.pval = c("none", "fisher", 
    "chi2")[1], vertical = TRUE, cap = "", lab = "", font.size = 
    "footnotesize", longtable = TRUE, nams = NA)

Arguments

vars A data frame of nominal variables. See nams for an alternative way of specifying the variables to be displayed.
weights Optional vector of weights of each observation.
subset Optional logical vector, indicates subset of observations to be used.
group Optional grouping variable.
miss.cat Vector specifying the factors in vars that should have their NAs transformed to a separate category.
print.pval Add p-values of Fisher's exact or chi^2 test for a difference of distributions between groups to the table, if there is more than one group.
vertical If TRUE, add vertical lines to the table, separating labels and groups, if applicable.
cap The caption of the resulting LaTeX table.
lab The label of the resulting LaTeX table.
font.size Font size for the generated table in LaTeX.
longtable If TRUE, function makes use of package longtable in LaTex to generate tables that span more than one page. If FALSE, generates a table in tabular environment.
nams A vector of strings, containing the names corresponding to the variables in vars, if vars is not a data frame but a list of variables. These are then the names that appear in the LaTeX table. This option is only kept for backward compatibility.

Value

Outputs the LaTeX table.

Warning

If either one of the arguments group, weights, or subset is different from NA and if vars is a list, then it is assumed that all variables in vars are of equal length.

Note

If longtable = TRUE (which is the default), the function generates a table that may be more than one page long, you need to include the package longtable in the LaTeX source.

If a list of variables is given to vars, not all of these variables need to be of the same length. However, note the Warning below.

Author(s)

Kaspar Rufibach (maintainer), kaspar.rufibach@ifspm.uzh.ch,
http://www.biostat.uzh.ch/aboutus/people/rufibach.html

References

Rufibach, K. (2009) reporttools: R-Functions to Generate LaTeX Tables of Descriptive Statistics. Journal of Statistical Software, Code Snippets, 31(1).
http://www.jstatsoft.org/v31/c01.

Examples

data(CO2)
vars <- CO2[, 1:2]
group <- CO2[, "Treatment"]
weights <- c(rep(1, 60), rep(0, 10), rep(2, 14))
     
## only consider a subset of observations
tableNominal(vars = vars, weights = weights, group = group, cap = 
    "Table of nominal variables.", lab = "tab: nominal")      

## only consider a subset of observations
subset <- c(1:50, 60:70)
tableNominal(vars = vars, weights = weights, subset = subset, group = group, 
    cap = "Table of nominal variables.", lab = "tab: nominal")     

[Package reporttools version 1.0.4 Index]