crosstab | R Documentation |
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
)
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 |
data.frame. Result of crossing the variables provided in ...
and
counting how many observations (rows) fall into each criteria.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.