The crosstab
function generates crosstabs (contingency tables) from survey data,
allowing for a variety of formatting and analytical options. It can produce tables with
statistical measures, create visual plots, and handle weighted data.
Arguments
- data
A data frame containing survey data. This parameter is required.
- rowVar
The independent variable represented in rows (side of the table).
- colVar
The dependent variable represented in columns (top of the table).
- weight
An optional variable containing weight factors for the analysis.
- totals
Logical; if
TRUE
, includes a totals column in the output (default isTRUE
).- round_decimals
Optional; number of decimal points for rounding the data (default is
NULL
).- statistics
Logical; if
TRUE
, calculates and prints Chi-Square, degrees of freedom (DF), Cramer's V, and p-value (default isFALSE
).- plot
Logical; if
TRUE
, generates a plot for visual representation of the crosstab data (default isFALSE
).- format
Specifies the output format: 'df_long', 'df_wide', 'csv', or 'statistics' (default is 'df_long').
- convert_to
Determines conversion type: 'percent' or 'frequency' (default is 'percent').
- yLab
Title for the Y-axis, default is "Population (%)".
- adjustX
Logical; if
TRUE
, adjusts the X-axis labels to a 45-degree angle for better readability (default isFALSE
).