Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round numbers in output to show small near-zero quantities as zero

I would like the output of my R console to look readable. To this end, I would like R to round all my numbers to the nearest N decimal places. I have some success but it doesn't work completely:

> options(scipen=100, digits=4)
> .000000001
[1] 0.000000001
> .1
[1] 0.1
> 1.23123123123
[1] 1.231

I would like the 0.000000001 to be displayed as simply 0. How does one do this? Let me be more specific: I would like a global fix for the entire R session. I realize I can start modifying things by rounding them but it's less helpful than simply setting things for the entire session.

like image 447
Alex Avatar asked Mar 31 '13 18:03

Alex


People also ask

What function is used to round a number towards zero?

To always round up (away from zero), use the ROUNDUP function. To always round down (toward zero), use the ROUNDDOWN function.

Can you round a number to zero?

0.499 is rounded to zero as 0. 0.5 is rounded to zero as 1. If the fractional part is more than or equal to 0.5, the number is rounded up to the next integer.

How do you show rounded numbers in Excel?

In the Format Cells window, switch to either Number or Currency tab, and type the number of decimal places you want to display in the Decimal places box. A preview of the rounded number will immediately show up under Sample. Click the OK button to save the changes and close the Format Cells dialog.


1 Answers

Look at ?options, specifically the digits and scipen options.

like image 66
Greg Snow Avatar answered Sep 25 '22 05:09

Greg Snow