Skip to contents

Rounds to significant digits similarly to signif.

Usage

signi(x, digits = 6)

Arguments

x

numeric vector to be rounded.

digits

number of significant digits required.

Value

numeric vector “close” to x, i.e. by at least digits significant digits.

Author

Martin Maechler, in prehistoric times (i.e. before 1990).

Note

This is really just round(x, digits - trunc(log10(abs(x)))) and hence mainly of didactical use. Rather use signif() otherwise.

See also

Examples

(x1 <- seq(-2, 4, by = 0.5))
#>  [1] -2.0 -1.5 -1.0 -0.5  0.0  0.5  1.0  1.5  2.0  2.5  3.0  3.5  4.0
identical(x1, signi(x1))# since 0.5 is exact in binary arithmetic
#> [1] TRUE
(x2 <- pi - 3 + c(-5,-1,0, .1, .2, 1, 10,100))
#> [1]  -4.858  -0.858   0.142   0.242   0.342   1.142  10.142 100.142
signi(x2, 3)
#> [1]  -4.858  -0.858   0.142   0.242   0.342   1.142  10.140 100.100