tab | R Documentation |
Function to calculate frequency distributions for categorical variables
tab( data, x, sort = FALSE, maxcat = NULL, minp = NULL, na.rm = FALSE, total = FALSE, digits = 2, cum = FALSE, plot = FALSE )
data |
A dataframe |
x |
A factor variable in the data frame. |
sort |
logical. Sort levels from high to low. |
maxcat |
Maximum number of categories to be included. Smaller categories will be combined into an "Other" category. |
minp |
Minimum proportion for a category to be included. Categories representing smaller proportions willbe combined into an "Other" category. maxcat and minp cannot both be specified. |
na.rm |
logical. Removes missing values when TRUE. |
total |
logical. Include a total category when TRUE. |
digits |
Number of digits the percents should be rounded to. |
cum |
logical. If |
plot |
logical. If |
The function tab
will calculate the frequency
distribution for a categorical variable and output a data frame
with three columns: level, n, percent.
If plot = TRUE
return a ggplot2 bar chart. Otherwise
return a data frame.
tab(cars74, carb) tab(cars74, carb, plot=TRUE) tab(cars74, carb, sort=TRUE) tab(cars74, carb, sort=TRUE, plot=TRUE) tab(cars74, carb, cum=TRUE) tab(cars74, carb, cum=TRUE, plot=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.