# rounding off problem.....

4 messages
Open this post in threaded view
|

## rounding off problem.....

 dear members....                                  here is a piece of my code: > tail(YLf14,15)  [1] 5.706871e-217 2.563877e-218 2.823295e-218 2.694622e-222 1.777409e-226  [6] 1.134403e-201 5.269464e-215 2.272121e-219 2.794970e-223 1.630978e-187 [11] 1.721529e-213 5.859815e-178 4.842612e-222 1.333685e-193 1.256051e-174 > YLf16 <- YLf14 + 0.001 > tail(YLf16,15)  [1] 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 [13] 0.001 0.001 0.001 Is there any way to avoid the rounding off of YLf16 to 0.001, and take exact values? very many thanks for your time and effort...... yours sincerely, AKSHAY M KULKARNI         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: rounding off problem.....

 "Is there any way ..." Two quick answers: 1. using base R functions and data types the answer is 'no' - a double (i.e. numeric) contains about 15 significant digits.     So 5.678e-100 is fine but   0.01 + 5.678e-100 will keep the .0100000000000000  as the significant digits and "drop" the digits 80 or so places further to the right. 2. there are packages that provide for arbitrary precision calculations     see R CRAN package Rmpfr      https://cran.r-project.org/web/packages/Rmpfr/vignettes/Rmpfr-pkg.pdfHTH, Eric On Fri, Mar 8, 2019 at 2:39 PM akshay kulkarni <[hidden email]> wrote: > dear members.... >                                  here is a piece of my code: > > > tail(YLf14,15) >  [1] 5.706871e-217 2.563877e-218 2.823295e-218 2.694622e-222 1.777409e-226 >  [6] 1.134403e-201 5.269464e-215 2.272121e-219 2.794970e-223 1.630978e-187 > [11] 1.721529e-213 5.859815e-178 4.842612e-222 1.333685e-193 1.256051e-174 > > YLf16 <- YLf14 + 0.001 > > tail(YLf16,15) >  [1] 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 > 0.001 > [13] 0.001 0.001 0.001 > > Is there any way to avoid the rounding off of YLf16 to 0.001, and take > exact values? > > very many thanks for your time and effort...... > yours sincerely, > AKSHAY M KULKARNI > > >         [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: rounding off problem.....

 In reply to this post by akshay kulkarni I'm no expert in R internals or floating point computation, however, two things come to mind. First, I suspect the exact value is stored. It is just the printing that looks rounded. That is likely because 0.001 completely dominates the rest. To print in full precision, you would need over 200 digits for some of your values. Second, you may be pushing the limits of precision. It seems to me your original values are indistinguishable from zero. If they really represent materially different values, you might want to rescale them to improve computational reliability. -- Kevin E. Thorpe Head of Biostatistics,  Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Assistant Professor, Dalla Lana School of Public Health University of Toronto email: [hidden email]  Tel: 416.864.5776  Fax: 416.864.3016   ﻿On 2019-03-08, 7:39 AM, "R-help on behalf of akshay kulkarni" <[hidden email] on behalf of [hidden email]> wrote:     dear members....                                      here is a piece of my code:         > tail(YLf14,15)      [1] 5.706871e-217 2.563877e-218 2.823295e-218 2.694622e-222 1.777409e-226      [6] 1.134403e-201 5.269464e-215 2.272121e-219 2.794970e-223 1.630978e-187     [11] 1.721529e-213 5.859815e-178 4.842612e-222 1.333685e-193 1.256051e-174     > YLf16 <- YLf14 + 0.001     > tail(YLf16,15)      [1] 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001     [13] 0.001 0.001 0.001         Is there any way to avoid the rounding off of YLf16 to 0.001, and take exact values?         very many thanks for your time and effort......     yours sincerely,     AKSHAY M KULKARNI             [[alternative HTML version deleted]]         ______________________________________________     [hidden email] 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.     ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: rounding off problem.....

 In reply to this post by Eric Berger dear EB,                  I checked the Rmpfr package. Thats exactly what I needed....! Thanks a lot. very many thanks for your time and effort, yours sincerely, AKSHAY M KULKARNI ________________________________ From: Eric Berger <[hidden email]> Sent: Friday, March 8, 2019 6:31 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] rounding off problem..... "Is there any way ..." Two quick answers: 1. using base R functions and data types the answer is 'no' - a double (i.e. numeric) contains about 15 significant digits.     So 5.678e-100 is fine but   0.01 + 5.678e-100 will keep the .0100000000000000  as the significant digits and "drop" the digits 80 or so places further to the right. 2. there are packages that provide for arbitrary precision calculations     see R CRAN package Rmpfr      https://cran.r-project.org/web/packages/Rmpfr/vignettes/Rmpfr-pkg.pdfHTH, Eric On Fri, Mar 8, 2019 at 2:39 PM akshay kulkarni <[hidden email]> wrote: dear members....                                  here is a piece of my code: > tail(YLf14,15)  [1] 5.706871e-217 2.563877e-218 2.823295e-218 2.694622e-222 1.777409e-226  [6] 1.134403e-201 5.269464e-215 2.272121e-219 2.794970e-223 1.630978e-187 [11] 1.721529e-213 5.859815e-178 4.842612e-222 1.333685e-193 1.256051e-174 > YLf16 <- YLf14 + 0.001 > tail(YLf16,15)  [1] 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 [13] 0.001 0.001 0.001 Is there any way to avoid the rounding off of YLf16 to 0.001, and take exact values? very many thanks for your time and effort...... yours sincerely, AKSHAY M KULKARNI         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.