Description Usage Arguments Details Value See Also Examples
This function creates a two way frequency table.
1 2 3 4 5 6 7 8 9 10 11 |
data |
data frame |
rowvar |
row factor (unquoted) |
colvar |
column factor (unquoted) |
type |
statistics to print. Options are |
total |
logical. if TRUE, includes total percents. |
na.rm |
logical. if TRUE, deletes cases with missing values. |
digits |
number of decimal digits to report for percents. |
chisquare |
logical. If |
plot |
logical. If |
Given a data frame, a row factor, a column factor, and a type (frequencies, cell percents, row percents, or column percents) the function provides the requested cross-tabulation.
If na.rm = FALSE
, a level labeled <NA>
added. If
total = TRUE
, a level labeled Total
is added. If
chisquare = TRUE
, a chi-square test of independence is
performed.
If plot=TRUE
, return a ggplot2 graph.
Otherwise the function return a list with 6 components:
table
(table). Table of frequencies or percents
type
(character). Type of table to print
total
(logical). If TRUE
, print row and or column totals
digits
(numeric). number of digits to print
rowname
(character). Row variable name
colname
(character). Column variable name
chisquare
(character). If chisquare=TRUE
, contains
the results of the Chi-square test. NULL
otherwise.
print.crosstab, plot.crosstab
1 2 3 4 5 6 7 8 9 10 11 12 | # print frequencies
crosstab(mtcars, cyl, gear)
# print cell percents
crosstab(mtcars, cyl, gear, type="percent")
# print column percents with chi-square test
crosstab(mtcars, cyl, gear, type="colpercent", chisquare=TRUE)
# plot row percents with chi-square test
crosstab(mtcars, cyl, gear, type="rowpercent", plot=TRUE,
chisquare=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.