freq | R Documentation |
Displays weighted or unweighted frequencies, including <NA> counts and proportions.
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 = "", display.type = TRUE, display.labels = st_options("display.labels"), headings = st_options("headings"), weights = NA, rescale.weights = FALSE, ... )
x |
Factor, vector, or data frame. |
var |
Optional unquoted variable name. Provides support for piped
function calls (e.g. |
round.digits |
Numeric. Number of significant digits to display.
Defaults to |
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 |
plain.ascii |
Logical. |
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 |
totals |
Logical. Set to |
report.nas |
Logical. Set to |
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 |
Characters to display in NA cells. Defaults to “”. |
display.type |
Logical. Should variable type be displayed? Default is
|
display.labels |
Logical. Should variable / data frame labels be
displayed? Default is |
headings |
Logical. Set to |
weights |
Vector of weights; must be of the same length as |
rescale.weights |
Logical parameter. When set to |
... |
Additional arguments passed to |
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).
A frequency table of class matrix
and summarytools
with
added attributes used by print method.
The data type represents the class
in most cases.
Dominic Comtois, dominic.comtois@gmail.com
table
data(tobacco) freq(tobacco$gender) freq(tobacco$gender, totals = FALSE) # Ignore NA's, don't show totals, omit headings freq(tobacco$gender, report.nas = FALSE, totals = FALSE, headings = FALSE) # In .Rmd documents, use the two following arguments, minimally freq(tobacco$gender, style="rmarkdown", plain.ascii = FALSE) # Grouped Frequencies with(tobacco, stby(diseased, smoker, freq)) (fr_smoker_by_gender <- with(tobacco, stby(smoker, gender, freq))) # Print html Source print(fr_smoker_by_gender, method = "render", footnote = NA) # Order by frequency (+ to -) freq(tobacco$age.gr, order = "freq") # Order by frequency (- to +) freq(tobacco$age.gr, order = "-freq") # Use the 'rows' argument to display only the 10 most common items freq(tobacco$age.gr, order = "freq", rows = 1:10) ## Not run: # Display rendered html results in RStudio's Viewer # notice 'view()' is NOT written with capital V # If working outside RStudio, Web browser is used instead # A temporary file is stored in temp dir view(fr_smoker_by_gender) # Display rendered html results in default Web browser # A temporary file is stored in temp dir here too print(fr_smoker_by_gender, method = "browser") # Write results to text file (.txt, .md, .Rmd) or html file (.html) print(fr_smoker_by_gender, method = "render", file = "fr_smoker_by_gender.md) print(fr_smoker_by_gender, method = "render", file = "fr_smoker_by_gender.html) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.