Description Usage Arguments Details Value Author(s) Examples
Creates an n-way table (cross-tabulation) with options to display results as weighted or unweighted counts, proportions or percentages, to include column, row or joint table totals and to control the number of decimal places used when reporting the output.
1 2 3 |
formula |
A formula specifying the variable(s) to be included in the cross-tabulation. (See details.) |
format |
A character string specifying the type of output required. The default is “ |
data |
A dataframe containing the variables to be cross-tabulated. |
na.rm |
A logical value ( |
cumsum |
A logical value ( |
margin |
A character string specifying what type of table margins are required. The default value is “ |
dp |
Integer. The number of decimal places to which results will be reported. The default is |
weights |
The name of a variable in the supplied dataframe to be used to weight the table. The default is |
flat |
A logical value indicating whether to return the table in ‘flat’ ( |
For univariate distributions, only include a variable name on the right-hand side of the the formula (e.g. ~ Tenure
). For bivariate distributions include a variable on both sides of the formula (e.g. Health ~ Tenure
). The variable on the left defines the rows; the variable on the right defines the columns. For higher dimensional distributions, include additional variables on the right-hand side of the formula (e.g. Health ~ Tenure + Sex
).
Returned as a table
data object, unless flat = TRUE
, in which case a ftable
data object is returned.
Paul Williamson
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ## n-way frequency counts
tally( ~Tenure, data=survey)
tally(Health ~ Tenure, data=survey)
tally(Health ~ Tenure + Sex, data=survey)
## Flat 3-way table
tally(Health ~ Tenure + Sex, data=survey, flat=TRUE)
## Add row/column/joint totals
tally(Health ~ Tenure, data=survey, margin = "row")
tally(Health ~ Tenure, data=survey, margin = "col")
tally(Health ~ Tenure, data=survey, margin = "joint")
## Report as percentages or proportions
tally(Health ~ Tenure, data=survey, margin = "col", format = "percent")
tally(Health ~ Tenure, data=survey, margin = "col", format = "proportion")
## Cumulative
tally(Health ~ Tenure, data=survey, margin = "col",
format = "percent", cumsum=TRUE)
## Weighted
tally(Health ~ Tenure, data=survey, margin = "col",
format = "percent", cumsum=TRUE, weight="Person_w0")
## Specify decimal places in reported output
tally(Health ~ Tenure, data=survey, margin = "col",
format = "percent", dp=4)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.