Displays weighted or unweighted frequencies, including <NA> counts and proportions.
Usage
freq(
x,
var = NULL,
round.digits = st_options("round.digits"),
order = "default",
style = st_options("style"),
plain.ascii = st_options("plain.ascii"),
justify = "default",
cumul = st_options("freq.cumul"),
totals = st_options("freq.totals"),
report.nas = st_options("freq.report.nas"),
rows = numeric(),
missing = "",
na.val = st_options("na.val"),
display.type = TRUE,
display.labels = st_options("display.labels"),
headings = st_options("headings"),
weights = NA,
rescale.weights = FALSE,
...
)Arguments
- x
Factor, vector, or data frame.
- var
Optional unquoted variable name. Provides support for piped function calls (e.g.
my_df %>% freq(my_var)).- round.digits
Numeric. Number of significant digits to display. Defaults to
2. Can be set globally withst_options.- order
Character. Ordering of rows in frequency table; “name” (default for non-factors), “level” (default for factors), or “freq” (from most frequent to less frequent). To invert the order, place a minus sign before or after the word. “-freq” will thus display the items starting from the lowest in frequency to the highest, and so forth.
- style
Character. Style to be used by
pander. One of “simple” (default), “grid”, “rmarkdown”, or “jira”. Can be set globally withst_options.- plain.ascii
Logical.
panderargument; whenTRUE, no markup characters will be used (useful when printing to console). Defaults toTRUEunlessstyle = 'rmarkdown', in which case it will be set toFALSEautomatically. Can be set globally withst_options.- justify
String indicating alignment of columns. By default (“default”), “right” is used for text tables and “center” is used for html tables. You can force it to one of “left”, “center”, or “right”.
- cumul
Logical. Set to
FALSEto hide cumulative proportions from results.TRUEby default. To change this value globally, seest_options.- totals
Logical. Set to
FALSEto hide totals from results.TRUEby default. To change this value globally, seest_options.- report.nas
Logical. Set to
FALSEto turn off reporting of missing values. To change this default value globally, seest_options.- rows
Character or numeric vector allowing subsetting of the results. The order given here will be reflected in the resulting table. If a single string is used, it will be used as a regular expression to filter row names.
- missing
Text to display in NA cells. Defaults to “”.
- na.val
Character. For factors and character vectors, consider this value as
NA. Ignored if there are actual NA values or if it matches no value / factor level in the data.NULLby default.- display.type
Logical. Should variable type be displayed? Default is
TRUE.- display.labels
Logical. Should variable / data frame labels be displayed? Default is
TRUE. To change this default value globally, seest_options.- headings
Logical. Set to
FALSEto omit heading section. Can be set globally viast_options.- weights
Vector of weights; must be of the same length as
x.- rescale.weights
Logical parameter. When set to
TRUE, the total count will be the same as the unweightedx.FALSEby default.- ...
Additional arguments passed to
pander.
Value
A frequency table of class matrix and summarytools with
added attributes used by print method.
Details
The default plain.ascii = TRUE option is there to make
results appear cleaner in the console. To avoid rmarkdown rendering
problems, this option is automatically set to FALSE whenever
style = "rmarkdown" (unless plain.ascii = TRUE is made
explicit in the function call).
Note
The data type represents the class in most cases.
Author
Dominic Comtois, dominic.comtois@gmail.com