Learn R Programming

questionr (version 0.8.0)

freqtable: Frequency table of variables

Description

Generate frequency tables for one or more variables in a data frame or a survey design.

Usage

freqtable(.data, ...)

# S3 method for default freqtable(.data, ..., na.rm = FALSE, weights = NULL)

# S3 method for survey.design freqtable(.data, ..., na.rm = FALSE, weights = TRUE)

Value

The result is an array of class `table`.

Arguments

.data

a data frame or `survey.design` object

...

one or more expressions accepted by select selecting at least one variable

na.rm

Whether to remove missing values in the variables.

weights

If `.data` is a data frame, an optional expression selecting a weighting variable. If `.data` is a survey design, either `TRUE` (the default) to to use survey weights, or `FALSE` or `NULL` to return unweighted frequencies.

See Also

freq, wtd.table, xtabs, table.

Examples

Run this code
data(hdv2003)
freqtable(hdv2003, nivetud, sport)
freqtable(hdv2003, nivetud, sport, sexe)
freqtable(hdv2003, nivetud, sport, weights=poids)
freqtable(hdv2003, starts_with("trav"))

# Using survey design objects
library(survey)
hdv2003_wtd <- svydesign(ids=~1, weights=~poids, data=hdv2003)
freqtable(hdv2003_wtd, nivetud, sport)

# Compute percentages based on frequencies
hdv2003 |> freqtable(sport) |> freq()
hdv2003 |> freqtable(sport, sexe) |> prop()
hdv2003 |> freqtable(sport, sexe) |> cprop()

Run the code above in your browser using DataLab