Format a statistic for display

Description

Formats numeric statistics with appropriate decimal places and leading zeros. Use for means, SDs, F, t, chi-square, MSE, b coefficients, etc.

Usage

format_stat(x, digits = 2, remove_leading_zero = FALSE)

Arguments

x Numeric value to format.
digits Integer. Number of decimal places. Default is 2.
remove_leading_zero Logical. If TRUE, removes leading zero for values between -1 and 1. Use for r, R², effect sizes. Default is FALSE.

Value

A character string.

Examples

[1] "3.46"
format_stat(0.234, remove_leading_zero = TRUE)
[1] ".23"
format_stat(-0.567, remove_leading_zero = TRUE)
[1] "-.57"