# displayKbyC: Function to display a K x C frequency table including col-... In reporttools: Generate "LaTeX"" Tables of Descriptive Statistics

## Description

Generate a LaTeX table of a K \times C frequency table that contains not only the cell frequencies, but also pre-specified row- and col-names as well as totals of rows and cols.

## Usage

 1 2 3 displayKbyC(v1, v2, percentage = c("none", "row", "col", "total")[1], names = c("v1", "v2"), cap = "", lab = "", row.nam = NA, col.nam = NA) 

## Arguments

 v1 Vector with integer entries. v2 Vector with integer entries. percentage Add percentages with respect to row, column, or table total. names Names of the vectors under consideration. cap Caption of the LaTeX table to be generated. lab Label of the LaTeX table to be generated. row.nam Labels of v1 to be given as row names. col.nam Labels of v2 to be given as column names.

## Value

Returns a LaTeX K x C table, together with the resulting computations. If you use this function in an .rnw file, you need to assign it to a (dummy) variable name in order for the results beyond the LaTeX table not to appear in the .tex file.

## Author(s)

Kaspar Rufibach (maintainer), kaspar.rufibach@gmail.com,
http://www.kasparrufibach.ch

## Examples

 1 2 3 4 5 set.seed(1977) v1 <- round(runif(20, 0, 3)) v2 <- round(runif(20, 0, 5)) displayKbyC(v1, v2, percentage = "row", names = c("v1", "v2"), cap = "", lab = "", row.nam = NA, col.nam = NA) 

### Example output

Loading required package: xtable
% latex table generated in R 4.0.3 by xtable 1.8-4 package
% Tue May 25 23:17:45 2021
\begingroup\footnotesize
\begin{longtable}{ll|cccccc|c}
&  & v2 &  &  &  &  &  &  \\
&  & 0 & 1 & 2 & 3 & 4 & 5 & Total \\
\hline
v1 & 0 & 0 (0\%) & 0 (0\%) & 1 (50.0\%) & 0 (0\%) & 1 (50.0\%) & 0 (0\%) & 2 (100.0\%) \\
& 1 & 1 (12.5\%) & 2 (25.0\%) & 0 (0\%) & 2 (25.0\%) & 2 (25.0\%) & 1 (12.5\%) & 8 (100.0\%) \\
& 2 & 2 (28.6\%) & 2 (28.6\%) & 1 (14.3\%) & 0 (0\%) & 1 (14.3\%) & 1 (14.3\%) & 7 (100.0\%) \\
& 3 & 1 (33.3\%) & 0 (0\%) & 2 (66.7\%) & 0 (0\%) & 0 (0\%) & 0 (0\%) & 3 (100.0\%) \\
\hline
& Total & 4 (20.0\%) & 4 (20.0\%) & 4 (20.0\%) & 2 (10.0\%) & 4 (20.0\%) & 2 (10.0\%) & 20 (100.0\%) \\
\hline
\caption{}
\label{}
\end{longtable}
\endgroup


reporttools documentation built on Oct. 12, 2021, 5:06 p.m.