[R] decimal troubles ?
Dear all, I have some trouble with the number of decimals in R (currently R 2.9.0). For instance: > options()$digits [1] 3 let me hope that I will get three digits where useful when a number is printed. BUT: > 44.25+31.1+50 [1] 125 No way to get the right result 125.35 Can anybody tell me what's happens ? Patrick __ R-help@r-project.org mailing list 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.
Re: [R] decimal troubles ?
Patrick Giraudoux wrote: > > I have some trouble with the number of decimals in R (currently R > 2.9.0). For instance: > > > options()$digits > [1] 3 > > let me hope that I will get three digits where useful when a number is > printed. BUT: > > > 44.25+31.1+50 > [1] 125 > > No way to get the right result 125.35 > It says digits, not decimals: > (44.25+31.1+50)/100 [1] 1.25 Dieter -- View this message in context: http://www.nabble.com/decimal-troubles---tp23498062p23498345.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] decimal troubles ?
Tena koe Patrick If you want more than three digits, change the options: options(digits=7) 44.25+31.1+50 [1] 125.35 HTH Peter Alspach > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Patrick Giraudoux > Sent: Tuesday, 12 May 2009 8:08 p.m. > To: r-help@r-project.org > Subject: [R] decimal troubles ? > > Dear all, > > I have some trouble with the number of decimals in R > (currently R 2.9.0). For instance: > > > options()$digits > [1] 3 > > let me hope that I will get three digits where useful when a > number is printed. BUT: > > > 44.25+31.1+50 > [1] 125 > > No way to get the right result 125.35 > > Can anybody tell me what's happens ? > > Patrick > > __ > R-help@r-project.org mailing list > 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. > The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited. __ R-help@r-project.org mailing list 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.
Re: [R] decimal troubles ?
Dieter Menne wrote: > > > It says digits, not decimals: > >> (44.25+31.1+50)/100 > [1] 1.25 > > Dieter > > > (44.25+31.1+50)*10 [1] 1254 Strictly speaking, this should print as 1250 (no flames, please, I can live with it) Dieter -- View this message in context: http://www.nabble.com/decimal-troubles---tp23498062p23498439.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] decimal troubles ?
> I have some trouble with the number of decimals in R (currently R > 2.9.0). For instance: > > > options()$digits > [1] 3 > > let me hope that I will get three digits where useful when a number is > printed. BUT: > > > 44.25+31.1+50 > [1] 125 > > No way to get the right result 125.35 > > Can anybody tell me what's happens ? The digits option specifies the number of significant figures, not the number of decimal places. (The help documentation on the options page doesn't make this clear at the moment, though it does point you to print.default, which describes it as setting significant digits.) Also note that the true value is being stored, so you can retrieve it with explicit formatting, e.g. x <- 44.25+31.1+50 x # 125 print(x, digits=5) # 125.35 Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list 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.
Re: [R] decimal troubles ?
Shame on me... I confused "digits" and "decimals" Thanks anyway to make me come to the English basics... Patrick Peter Alspach a écrit : > Tena koe Patrick > > If you want more than three digits, change the options: > > options(digits=7) > 44.25+31.1+50 > [1] 125.35 > > HTH > > Peter Alspach > > >> -Original Message- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of Patrick Giraudoux >> Sent: Tuesday, 12 May 2009 8:08 p.m. >> To: r-help@r-project.org >> Subject: [R] decimal troubles ? >> >> Dear all, >> >> I have some trouble with the number of decimals in R >> (currently R 2.9.0). For instance: >> >> > options()$digits >> [1] 3 >> >> let me hope that I will get three digits where useful when a >> number is printed. BUT: >> >> > 44.25+31.1+50 >> [1] 125 >> >> No way to get the right result 125.35 >> >> Can anybody tell me what's happens ? >> >> Patrick >> >> __ >> R-help@r-project.org mailing list >> 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. >> >> > > The contents of this e-mail are confidential and may be subject to legal > privilege. > If you are not the intended recipient you must not use, disseminate, > distribute or > reproduce all or any part of this e-mail or attachments. If you have > received this > e-mail in error, please notify the sender and delete all material pertaining > to this > e-mail. Any opinion or views expressed in this e-mail are those of the > individual > sender and may not represent those of The New Zealand Institute for Plant and > Food Research Limited. > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.