Learn R Programming

surveytable (version 0.9.7)

tab_rate: Calculate rates

Description

Calculate the rates for categorical (factor) or logical variables.

Usage

tab_rate(
  vr,
  pop,
  per = getOption("surveytable.rate_per"),
  drop_na = getOption("surveytable.drop_na"),
  max_levels = getOption("surveytable.max_levels"),
  csv = getOption("surveytable.csv")
)

Value

A list of tables or a single table.

Arguments

vr

variable to tabulate

pop

either a single number or a data.frame with columns named Level and Population. Level must exactly match the levels of vr. Population is the population for that level of vr.

per

calculate rate per this many items in the population

drop_na

drop missing values (NA)?

max_levels

a categorical variable can have at most this many levels. Used to avoid printing huge tables.

csv

name of a CSV file

See Also

Other tables: tab(), tab_cross(), tab_subset_rate(), total(), total_rate()

Examples

Run this code
set_survey(namcs2019sv)
# pop is a data frame
tab_rate("MSA", uspop2019$MSA)

# pop is a single number
tab_rate("MDDO", uspop2019$total)

Run the code above in your browser using DataLab