[R] Round down numeric values with decimals
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Tue Sep 4 20:08:07 CEST 2018
This is *not* "rounding down."
But this should do it I think:
## (see ?floor)
x <- 3.896e09
k <- floor(log10(x))
> floor(x*10^(-k))*10^k
[1] 3e+09
There may be even slicker ways, but this is as slick as I can muster...
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Sep 4, 2018 at 9:33 AM Nelly Reduan <nell.redu using hotmail.fr> wrote:
> Hello,
>
>
>
> How can I round down numeric values with decimals? For example,
>
>
>
> > signif(3.896037e+09, digits = 1)
>
> [1] 4e+09
>
>
>
> The expected result is 3e+09 (and not 4e+09).
>
>
>
> > signif(8.68542378e-10, digits = 1)
>
> [1] 9e-10
>
>
>
> The expected result is 8e-10 (and not 9e-10).
>
>
>
> Thank you very much for your time.
>
> Have a nice day
>
> Nell
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list