| apa | R Documentation |
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.
apa(value, decimals = 3, leading = TRUE)
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'. |
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.
A character vector/array (matching the shape of 'value') containing the formatted numbers.
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"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.