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.
To always round up (away from zero), use the ROUNDUP function. To always round down (toward zero), use the ROUNDDOWN function.
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.
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.
Look at ?options
, specifically the digits
and scipen
options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With