t_td: TexHelp round/signif chars

Description Usage Arguments Details Value Examples

View source: R/texhelp.R

Description

t_td forces there to be d digits after the decimal for the numeric input x, without messing with the "integer part" of x; t_sd messes with the integer part (i.e. uses significant digits). Both are vectorized over x.

Usage

1
2
3
t_td(x, d = 0, commas = TRUE, except = c())

t_sd(x, d = 1, commas = TRUE, except = c())

Arguments

x

numeric to clean; if not numeric, will be coerced

d

number of trailing digits (for t_td) or significant digits (for t_sd)

commas

whether to insert commas in the number (the default)

except

do not modify these positions of the vector

Details

t_td ("texhelp trailing digits") returns a character vector version of x, rounded or expanded with trailing digits so that there are exactly d digits after the decimal point. That is, rounding is done or 0s are added to the end as needed.

t_sd ("texhelp significant digits") returns a character vector version of x so that there are exactly d significant digits shown. Trailing zeroes are added as needed, to make the point that there are actually d significant digits.

(In most cases you will want to use t_td in order to force a list of numbers to have the same number of trailing digits – this looks better.)

In both functions, commas are added where necessary; turn off with commas=FALSE.

The except parameter is included to make it painless to deal with the common case of an identifying column for which you do not want trailing digits.

Value

a cleaned charater vector version of the numeric

Examples

1
2
t_td(c(123.2,1.231, 1.8764, 1543.999,1532.987),d=2)
t_sd(c(2342.232,232.213,323.23,0.99999),d=2)

rdisalv2/dismisc documentation built on March 19, 2018, 9:12 a.m.