# 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')
Run the code above in your browser using DataLab