apa: Format numbers for APA-style reporting

View source: R/apa.R

apaR Documentation

Format numbers for APA-style reporting

Description

Create "pretty" character representations of numeric values with a fixed number of decimal places, optionally keeping or omitting the leading zero for values between -1 and 1.

Usage

apa(value, decimals = 3, leading = TRUE)

Arguments

value

Numeric input: a single number, vector, matrix, or a data frame with all-numeric columns. Non-numeric inputs will error.

decimals

A single non-negative integer giving the number of decimal places to keep in the output.

leading

Logical: 'TRUE' to keep leading zeros on decimals (e.g., '0.25'), 'FALSE' to drop them (e.g., '.25'). Default is 'TRUE'.

Details

This function formats numbers for inclusion in manuscripts and reports. - When 'leading = TRUE', numbers are rounded and padded to 'decimals' places, keeping the leading zero for values with absolute value < 1. - When 'leading = FALSE', the leading zero before the decimal point is removed for values with absolute value < 1. If 'value' is a data frame, all columns must be numeric; otherwise an error is thrown.

Value

A character vector/array (matching the shape of 'value') containing the formatted numbers.

Examples

apa(0.54674, decimals = 3, leading = TRUE)   # "0.547"
apa(c(0.2, 1.2345, -0.04), decimals = 2)     # "0.20" "1.23" "-0.04"
apa(matrix(c(0.12, -0.9, 2.3, 10.5), 2), decimals = 1, leading = FALSE)
# returns a character matrix with ".1", "-.9", "2.3", "10.5"

MOTE documentation built on Dec. 15, 2025, 9:06 a.m.

Related to apa in MOTE...