tableNominal {reporttools} | R Documentation |
Many data analyses start with a display of descriptive statistics of important variables. This function takes a list of nominal variables and a possible grouping variable (such as e.g. treatment) and provides a LaTeX table of descriptive statistics separately per group and jointly for all observations, per variable.
tableNominal(vars, nams, weights = NA, subset = NA, group = NA, miss.cat = NA, print.pval = c("none", "fisher", "chi2")[1], vertical = TRUE, cap = "", lab = "")
vars |
A list of nominal variables. |
nams |
A vector of strings, containing the names corresponding to the variables in vars . These are the names
that appear in the LaTeX table. |
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 NA s transformed to a separate category. |
print.pval |
Give p-value of Fisher's exact or chi^2 test for a difference of distributions between groups, 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. |
Outputs the LaTeX table.
If either one of the arguments group
, weights
, or subset
is different from NA
, then it
is assumed that all variables in vars
are of equal length.
Kaspar Rufibach (maintainer), kaspar.rufibach@ifspm.uzh.ch,
http://www.biostat.uzh.ch/aboutus/people/rufibach.html
Rufibach, K. (2009) reporttools: R-Functions to Generate LaTeX Tables of Descriptive Statistics. Journal of Statistical Software, to appear.
set.seed(1977) vars <- list(c(round(runif(90, 0, 3)), rep(NA, 10)), round(runif(100, 0, 2))) nams <- c("Var1", "Var2") group <- sample(c(rep("A", 50), rep("B", 50))) weights <- c(rep(1, 70), rep(2, 20), rep(1, 10)) ## only consider a subset of observations (use of 'subset' is no longer recommended, though!) tableNominal(vars, nams, weights = weights, group = group, cap = "Table of nominal variables.", lab = "tab: nominal") ## only consider a subset of observations (use of 'subset' is no longer recommended, though!) subset <- c(1:70, 91:100) tableNominal(vars, nams, weights = weights, subset = subset, group = group, cap = "Table of nominal variables.", lab = "tab: nominal")