R round exponential number
I just trying to round in R number like:
> round(1.327076e-09)
I would like开发者_高级运维 it to result in
> 1.33e-09
but results in
> 0
which function can use?
Try signif
:
> signif(1.326135235e-09, digits = 3)
[1] 1.33e-09
Use signif
:
x <- 1.327076e-09
signif(x,3)
[1] 1.33e-09
or sprintf
:
sprintf("%.2e",x)
[1] "1.33e-09"
The function round
will do rounding and you can specify the number of decimals:
x <- 1.327076e-09
round(x, 11)
[1] 1.33e-09
Rising to the challenge set by @Joris and @GavinSimpson - to use trunc
on this problem, do the following:
library(plyr)
round_any(x, 1e-11, floor)
[1] 1.32e-09
精彩评论