tbl: Create a simple table showing counts and column proportions

Description Usage Arguments Value Author(s) See Also Examples

Description

This function will calculate counts and column proportions for a one-way or two-way table.

Usage

1
2
3
4
5
## Default S3 method:
tbl(x, ...)
## S3 method for class 'formula'
tbl(formula, data = NULL, ..., subset,
   na.action = NULL, overall = FALSE, overall.label = "Overall")

Arguments

x

The variable for which to report counts and proportions.

formula

A formula with the row variable on the left hand side and the column variable(s) on the right hand side. Think of this as rowvar ~ colvar.

data

A data.frame from which the variables in formula should be taken.

subset

An optional vector specifying a subset of observations to be used for the calculations.

na.action
overall

If TRUE, then an overall summary is included. The default is FALSE.

overall.label

If overall = TRUE, then this string is the identifier for the overall summary. The default is "Overall" but in the unlikely event that "Overall" is already a level in the data set then overall.label can be changed to something like "All".

Value

For single-variable, or univariate, tables, the result is a numeric matrix with rows representing the levels of the variable and two columns. The first column contains the number and the second column contains the percentage.

For two-variable tables, the result is a list with each element being a matrix having column 1 be the counts and column 2 be the percentages.

Author(s)

Stephen Weigand Weigand.Stephen@mayo.edu

See Also

table, ftable, xtabs

Examples

1
2
3
4
5
data(sleep)
tbl(sleep$group)
sleep$outcome <- factor(ifelse(sleep$extra <= 2, "Low", "High"),
                        levels = c("Low", "High"))
tbl(outcome ~ group, data = sleep)

summarize documentation built on May 2, 2019, 6:51 p.m.