I want to format figures with 2 significant digits using formatC
. But it has a strange behaviour. Here are the figures:
(x <- data.frame( cil = c(1.234, 0.444, 0.712, 0.999, 1.999)
, ciu = c(1.812, 1.234, 0.999, 1.199, 2.690)
)
)
x$ci <- with(x,paste("("
, formatC(cil, format="g", digits=2, flag="#")
, "-"
, formatC(ciu, format="g", digits=2, flag="#")
,")"
)
)
x
And here are the results:
cil ciu ci
1 1.234 1.812 ( 1.2 - 1.8 )
2 0.444 1.234 ( 0.44 - 1.2 )
3 0.712 0.999 ( 0.71 - 1.0 )
4 0.999 1.199 ( 1.0 - 1.2 )
5 1.999 2.690 ( 2. - 2.7 )
In case 5 I expected 2.0 and not 2.. Is there an explanation for this? Did I something wrong with the definition of the parameters?