snip: Remove leading zero and/or trailing zero from a statistic

Description Usage Arguments Value Leading zero Trailing zero Examples

Description

Use snip() if you need to trim a leading zero (left of decimal) or trailing zero (right of decimal) from a value (esp. for reporting stats in APA format).

Usage

1
snip(x, lead = NULL, trail = 3)

Arguments

x

A numeric value, coercible to a character.

lead

Optional number of zeros to remove from the left of the decimal. Default is NULL. See Leading Zero for details.

trail

Position for evaluating whether a trailing zero should be dropped? Defaults to 3. See Trailing Zero for details.

Value

x as a string with leading and/or trailing zero removed.

Leading zero

For values that cannot exceed 1, (e.g., p values), APA recommends removing the zero to the left of the decimal.

For example p = 0.023 should be reported as p = .023. In this case, snip(0.023), lead = 1 would work.

If, for some reason, you need to snip more than one zero, you can specify the number.

Only exact matches (e.g., 1 or 2 "0"s, set by lead) for x < 1 will be snipped; otherwise, the value to the left of the decimal is left unchanged.

Trailing zero

The APA recommends reporting statistics with decimal fractions rounded to two or three places (in most circumstances).

When trail = 3, the default behavior is to assume that a minimium of 2 places after the decimal should be preserved under all conditions. This basically sets the position being evaluated = 3, and assumes the APA-recommended floor threshold of .001: If there is a zero in this position, the zero is snipped.

See examples and APA_p.

Examples

1
2
3
4
5
# Drop leading zero
cat(snip("0.22",1))

# Drop trailing zero
cat(snip("0.220"))

darrellpenta/APAstyler documentation built on May 14, 2019, 6:10 p.m.