format_statistics: Format statistics

View source: R/format_statistics.R

format_statisticsR Documentation

Format statistics

Description

The results of function statistics must be formated before printing. format_statistics does this.

Usage

format_statistics(x, ...)

## S3 method for class 'statistics_numeric'
format_statistics(x, format_statistics.statistics_numeric = NULL, ...)

## S3 method for class 'statistics_factor'
format_statistics(x, format_statistics.statistics_factor = NULL, ...)

## S3 method for class 'statistics_count_me'
format_statistics(x, ...)

## Default S3 method:
format_statistics(x, ...)

Arguments

x

An object.

...

Passed from and to other methods.

format_statistics.statistics_numeric

Either NULL or a function. Default is NULL. If a function, then it will replace atable:::format_statistics.statistics_numeric. The function must mimic format_statistics: arguments are x and the ellipsis ... . Result is a non-empty data.frame with 2 columns called 'tag' and 'value'.

format_statistics.statistics_factor

Analog to argument format_statistics.statistics_numeric

Details

This function defines which statistics are printed in the final table and how they are formated.

The format depends on the class x. See section methods.

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

Value

A non-empty data.frame with 2 columns called 'tag' and 'value'. Column 'tag' has class factor and no duplicates. Column 'value' is a character. See also function check_format_statistics.

Methods (by class)

  • format_statistics(statistics_numeric): Defines how to format class statistics_numeric. Returns a data.frame with 2 rows. Column 'tag' contains 'Mean_SD' and 'valid_missing'. Column 'value' contains two values: first value is the rounded mean and standard deviation, pasted them together. The standard deviation is bracketed. Second value is the number of non-missing and missing values pasted together. The number of missing values is bracketed.

  • format_statistics(statistics_factor): Defines how to format class statistics_factor. Returns a data.frame. Column 'tag' contains all names of x. Column 'value' contains the percentages and the total number of values in brackets.

  • format_statistics(statistics_count_me): Defines how to format class statistics_count_me. Returns a data.frame. Column 'tag' contains the empty character ''. The empty character is choosen because colname_for_observations already appears in the final table. Column 'value' contains the number of observations. See also 'colname_for_observations' in atable_options.

  • format_statistics(default): Returns a data.frame. Column 'tag' contains all names of x. Column 'value' contains all elements of x, rounded by format.


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