| table2 | R Documentation |
The function table does not show variable
names when tabulating from a dataframe, requires running another
function, prop.table, to tabulate proportions
and yet another function, chisq.test to test difference of
proportions. table2 does what those three functions do, producing easier to
read output, and always shows variable names.
... |
same arguments as |
prop |
report a table with:
|
digits |
Number of decimal values to show for proportions |
chi |
Logical. If |
correct |
Logical. If |
A list (object of class "table2") with the following components:
freq: frequency table
prop: proportions table
chisq: chi-square test
# Create example data
df <- data.frame(
group = c("A", "A", "B", "B", "A"),
status = c("X", "Y", "X", "Y", "X")
)
# Enhanced table with variable names (2 variables)
table2(df$group, df$status)
# Enhanced table with variable names (3 variables)
df3 <- data.frame(
x = c("A", "A", "B", "B"),
y = c("X", "Y", "X", "Y"),
z = c("high", "low", "high", "low")
)
table2(df3$x, df3$y, df3$z)
# Table with proportions
table2(df$group, df$status, prop = 'all') # Overall proportions
table2(df$group, df$status, prop = 'row') # Row proportions
table2(df$group, df$status, prop = 'col') # Column proportions
# Table with chi-square test
table2(df$group, df$status, chi = TRUE,prop='all')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.