freq {descr}R Documentation

Frequency table

Description

Prints a frequency table of the selected object. Optionally, the frequency might be weighted.

Usage

freq(x, w, user.missing, plot = getOption("descr.plot"), ...)

Arguments

x

The factor from which the frequency of values is desired.

w

An optional vector for a weighted frequency table.

user.missing

Character vector, indicating what levels must be treated as missing values while calculating valid percents. Levels representing user missing values are not shown in the barplot.

plot

Logical: if TRUE (default), a barplot is produced. You may put

options(descr.plot = FALSE)

in your ‘.Rprofile’ to change the default function behavior.

...

Further arguments to be passed to plot.freqtable if plot = TRUE.

Details

A column with cumulative percents are added to the frequency table if x is an ordered factor.

Value

A matrix with class c("matrix", "freqtable") with the attribute "xlab" which is a character string corresponding to either the attribute "label" of x or, if x does not have this attribute, the name of x. The returned object can be plotted, generating a barplot.

Author(s)

Jakson A. Aquino jalvesaq@gmail.com, based on function written by Dirk Enzmann

Examples

x <- c(rep(1, 100), rep(2, 120), rep(3, 10), rep(NA, 12))
w <- c(rep(1.1, 122), rep(0.9, 120))
x <- factor(x, levels = c(1, 2, 3),
            labels = c("No", "Yes", "No answer"))
attr(x, "label") <- "Do you agree?"

freq(x, y.axis = "percent")
f <- freq(x, w, user.missing = "No answer", plot = FALSE)
f
plot(f)

# If the decimal separator in your country is a comma:
# options(OutDec = ",")
library(xtable)
print(xtable(f))

[Package descr version 1.1.8 Index]