Just to elaborate on Marc's comment: > set.seed(42) > x <- runif(1) > dput(x) # What R is storing as x 0.914806043496355 > print(x) # Ways to display an approximation of x [1] 0.914806 > print(x, digits=3) [1] 0.915 > round(x, 2) [1] 0.91 > signif(x, 4) [1] 0.9148 > library(MASS) > fractions(x) [1] 7334/8017 > dput(x) # But x is still the same 0.914806043496355
David L. Carlson Department of Anthropology Texas A&M University -----Original Message----- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marc Schwartz Sent: Monday, October 26, 2015 2:40 PM To: Judson <judsonbl...@msn.com> Cc: R-help <r-help@r-project.org> Subject: Re: [R] Number of digits to display? > On Oct 26, 2015, at 11:43 AM, Judson <judsonbl...@msn.com> wrote: > > How do I control the number of digits to display, > say, in a matrix, without rounding or losing accuracy > in subsequent calculations? > round() of course reduces accuracy. > > Also, if all my results > are really fractions, is there a way to display > them as fractions of integers rather than > decimal expressions? > > ................... judson blake Hi, You need to differentiate between the way in which R *stores* numeric values and the way in which it *displays* numeric values. If you want to affect the display of values in routine output, see ?options and note 'digits' and 'scipen'. Also see ?print.default. Those approaches do not affect the precision of calculations on the *stored* values. For fractions, see: require(MASS) ?fractions Regards, Marc Schwartz ______________________________________________ R-help@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. ______________________________________________ R-help@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.