Learn R Programming

summarytools (version 0.8.0)

freq: Frequency Tables for Factors and Other Discrete Data

Description

Displays weighted or unweighted frequencies, including <NA> counts and proportions.

Usage

freq(x, round.digits = 2, order = "names", style = "simple",
  plain.ascii = TRUE, justify = "default", omit.headings = FALSE,
  missing = "", display.type = TRUE, display.labels = TRUE,
  weights = NA, rescale.weights = FALSE, ...)

Arguments

x

Factor or vector

round.digits

Number of significant digits to display. Defaults to 2.

order

Ordering of rows in frequency table; “names” (default for non-factors), “levels” (default for factors), or “freq” (from most frequent to less frequent).

style

Style to be used by pander when rendering output table; One of “simple” (default), “grid” or “rmarkdown”.

plain.ascii

Logical pander argument. When TRUE, no markup characters will be used (useful when printing to console). Defaults to TRUE when style is “simple”, and FALSE otherwise.

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”.

omit.headings

Logical. Set to TRUE to omit headings.

missing

Characters to display in NA cells. Defaults to “”.

display.type

Logical. Should variable type be displayed? Default is TRUE.

display.labels

Logical. Should variable / data frame labels be displayed? Default is TRUE.

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 unweighted x. FALSE by default.

Additional arguments passed to pander.

Value

A frequency table of class matrix with added attributes used by the print method.

Details

The default plain.ascii = TRUE option is there to make results appear cleaner in the console. To avoid rmarkdown rendering problems, the option is automatically set to FALSE whenever style = "rmarkdown" (unless plain.ascii = TRUE is made explicit).

See Also

table

Examples

Run this code
# NOT RUN {
data(tobacco)
freq(tobacco$gender)
freq(tobacco$gender, style="rmarkdown")
with(tobacco, by(smoker, gender, freq))

# }

Run the code above in your browser using DataLab