statistics: Calculates descriptive statistics

View source: R/statistics.R

statisticsR Documentation

Calculates descriptive statistics

Description

Calculates descriptive statistics depending on the class of its input.

Usage

statistics(x, ...)

## S3 method for class 'numeric'
statistics(x, statistics.numeric = NULL, ...)

## S3 method for class 'factor'
statistics(x, statistics.factor = NULL, ...)

## S3 method for class 'logical'
statistics(x, labels_TRUE_FALSE = atable_options("labels_TRUE_FALSE"), ...)

## S3 method for class 'character'
statistics(x, ...)

## S3 method for class 'ordered'
statistics(x, statistics.ordered = NULL, ...)

## S3 method for class 'count_me'
statistics(x, ...)

Arguments

x

An object. Statistics will be calculated of x.

...

Passed from and to other methods.

statistics.numeric

Either NULL or a function. Default is NULL. If a function, then it will replace atable:::statistics.numeric. The function must mimic statistics: arguments are x and the ellipsis ... . Result is a named list with length > 0 with unique names.

statistics.factor

Analog to argument statistics.numeric

labels_TRUE_FALSE

For relabeling logicals. See also atable_options.

statistics.ordered

Analog to argument statistics.numeric

Details

Calculates descriptive statistics depending on the class of its input.

Results are passed to function format_statistics.

If you are not pleased with the current descriptive statistics you may alter these functions. But you must keep the original output-format, see section Value. Function check_statistics checks if the output of statistics is suitable for further processing.

Value

The results of statistics are passed to function format_statistics. So the results of statistics must have a class for which the generic format_statistics has a method.

format_statistics has a default method, which accepts lists. So the results of statistics can be a named list with length > 0. The names of the list must have no duplicates.

Function check_statistics checks if the output of statistics is suitable for further processing.

Methods (by class)

  • statistics(numeric): Descriptive statistics are: length, number of missing values, mean and standard deviation. Class of the result is 'statistics_numeric' and there is a method format_statistics_to_Latex.statistics_numeric. This function is meant for interval scaled variables.

  • statistics(factor): Counts the numbers of occurrences of the levels of x with function table. This function is meant for nominal and ordinal scaled variables.

  • statistics(logical): Casts x to factor, then applies statistics again. The labels for TRUE and FALSE can also be modfied by setting atable_options('labels_TRUE_FALSE').

  • statistics(character): Casts x to factor, then applies statistics again.

  • statistics(ordered): Casts x to factor, then applies statistics again.

  • statistics(count_me): Returns the length of x. For class 'count_me' see add_observation_column.


atable documentation built on Sept. 17, 2023, 5:06 p.m.