report.ordinal: Report the distributions of ordinal variables

View source: R/report.ordinal.R

report.ordinalR Documentation

Report the distributions of ordinal variables

Description

This function reports statistics for ordinal variables in a dataset. It calculates proportions or counts of each level, the total count of valid (non-NA) entries, mean, and standard deviation.

Usage

report.ordinal(
  ordVarNames,
  data,
  type = 1,
  dec = 1,
  dec.freq = 0,
  language = "english",
  attachLabels = FALSE
)

Arguments

ordVarNames

A vector of strings representing the names of the ordinal variables in the dataset.

data

A data frame or an object of class survey.design from survey package.

type

An integer indicating the type of the report: 1 = proportions (default), 2 = counts, 3 = counts and proportions.

dec

The number of decimal places to round the values.

dec.freq

Number of decimal places for frequencies. Defaults is 0. Only used when an object of class survey.design is specified with the parameter data.

language

The language used for displaying the statistics in the frequency table. This parameter accepts two values: english or slovene. Depending on the chosen language, all statistical terms and output will be adjusted accordingly. Default is english.

attachLabels

Logical, if TRUE, attempts to attach variable labels from the attributes of the data frame. By default, attachLabels = FALSE.

Value

A matrix with rows representing each specified ordinal variable, and columns representing: 1) proportions or counts (or both) of each level (one column per level), 2) total count of valid (non-NA) entries, 3) mean, 4) standard deviation.

Author(s)

Marjan Cugmas

Examples

data <- data.frame(A = factor(c(1, 2, 3, 2), ordered = TRUE),
                   B = factor(c(2, 3, 2, 1), ordered = TRUE))
ordVarNames <- c("A", "B")
report.ordinal(ordVarNames, data, type = 1)

handyReport documentation built on Oct. 8, 2024, 3 p.m.