| crosstab {lares} | R Documentation |
Weighted Cross Tabulation
Description
A cross-tabulation function with output similar to STATA, tidy friendly, with weighting possibility.
Usage
crosstab(
df,
...,
wt = NULL,
prow = FALSE,
pcol = FALSE,
pall = FALSE,
decimals = 2,
rm.na = FALSE,
total = TRUE,
order = TRUE
)
Arguments
df |
Data.frame. |
... |
Variables. Dependent and independent variables. |
wt |
Variable, numeric. Weights. |
prow, pcol, pall |
Boolean. Calculate percent values for rows, columns, or the whole table, respectively. |
decimals |
Integer. How many decimals should be returned? |
rm.na |
Boolean. Remove NA values? |
total |
Boolean. Return total values column? |
order |
Boolean. Sort columns and rows by frequencies? Else, will be sorted alphabetically |
Value
data.frame. Result of crossing the variables provided in ... and
counting how many observations (rows) fall into each criteria.
See Also
Other Exploratory:
corr_cross(),
corr_var(),
df_str(),
distr(),
freqs_df(),
freqs_list(),
freqs_plot(),
freqs(),
lasso_vars(),
missingness(),
plot_cats(),
plot_df(),
plot_nums(),
tree_var()
Examples
data(dft) # Titanic dataset
crosstab(dft, Survived, Pclass, total = FALSE)
# Show values in percentages
crosstab(dft, Pclass, Survived, prow = TRUE)
crosstab(dft, Pclass, Survived, pall = TRUE)
# Weighted by another variable
crosstab(dft, Survived, Pclass, wt = Fare, prow = TRUE)