Learn R Programming

SciencesPo (version 1.3.7)

freq: Frequency table

Description

Computes absolute and relative frequencies of a vector x. Continuous (numeric) variables are cut as the hist function, whereas categorical variables are aggregated by table.

Usage

freq(x, weighs = NULL, breaks = hist(x, plot = FALSE)$breaks, digits = 2,
  include.lowest = TRUE, ord = c("level", "desc", "asc", "name"),
  useNA = c("no", "ifany", "always"), ...)

Arguments

x
The variable to be described.
weighs
a numeric vector of weights.
breaks
Either a numeric vector of two or more cut points or a integer (> 2) for the intervals. If not provided, the default is taken from hist(). This parameter is ignored if x is not of class numeric.
digits
An integer for the decimals.
include.lowest
A logical, indicating if an x[i] equal to the lowest (or highest, for right = FALSE) "breaks" value should be included. Ignored if x is not of numeric type.
ord
How should the result be ordered. Default is "level", other choices are by frequency: ("desc" or "asc") or 'by name of the levels' ("name").
useNA
A character parameter to be passed to table.
...
Further arguments are: cut(), and right to define if the intervals should be closed on the right (and open on the left) or vice versa.

Examples

Run this code
data(ssex)
with(ssex, freq(Favor))

# sorted by frequency
freq(ssex$Favor, ord="desc")

# sorted by name, including NAs
with(ssex, freq(Favor, ord="name", useNA="ifany"))

Run the code above in your browser using DataLab