
A cross-tabulation function with output similar to STATA, tidy friendly, with weighting possibility.
crosstab(
df,
...,
wt = NULL,
prow = FALSE,
pcol = FALSE,
pall = FALSE,
decimals = 2,
rm.na = FALSE,
total = TRUE,
order = TRUE
)
data.frame. Result of crossing the variables provided in ...
and
counting how many observations (rows) fall into each criteria.
Data.frame.
Variables. Dependent and independent variables.
Variable, numeric. Weights.
Boolean. Calculate percent values for rows, columns, or the whole table, respectively.
Integer. How many decimals should be returned?
Boolean. Remove NA values?
Boolean. Return total values column?
Boolean. Sort columns and rows by frequencies? Else, will be sorted alphabetically
Other Exploratory:
corr_cross()
,
corr_var()
,
df_str()
,
distr()
,
freqs()
,
freqs_df()
,
freqs_list()
,
freqs_plot()
,
lasso_vars()
,
missingness()
,
plot_cats()
,
plot_df()
,
plot_nums()
,
tree_var()
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)
Run the code above in your browser using DataLab