Reputation: 31
Is there a way to globally control the number of decimal places that show up in the print output in R? By globally, I mean something I can run at the beginning of an R session which applies to everything in that session. The default for me appears to be 6 decimals but I don't need that level of detail. I would like to accomplish this using base R, without using round() or any other formatting function at the prompt.
For example, assume I would like everything to print to 4 decimal places. Therefore I want 123.123 to appear as 123.1230, 123.123123 as 123.1231, and 123 as 123.0000, etc. Digits() won't accomplish this as it limits the entire output to the number of digits I specify.
Upvotes: 2
Views: 10614
Reputation: 603
You can set it globally
getOption("digits")
[1] 6
x <- 10.30429032
options("digits" = 4)
x
[1] 10.3
options("digits" = 6)
x
[1] 10.3043
Upvotes: 1