[R] Fractional component of a number

Jim Holtman jholtman at gmail.com
Sun Aug 28 13:05:05 CEST 2011


FAQ 7.31

Sent from my iPad

On Aug 27, 2011, at 23:59, edward.m at psu.ac.th wrote:

> Dear all,
> I am happy to accept that
> 
>> is.integer(1)
> [1] FALSE
> 
> But I'm having difficulty with this one:
> 
>> as.integer((2.53-2)*100)
> [1] 52
> 
> especially since:
> 
>> as.integer((1.53-1)*100)
> [1] 53
> 
> Although I know that this is a precision issue since
> 
>> x <- (2.53-2)*100
>> x-53
> [1] -2.131628e-14
> 
> And I can always use the round function to get what I want, but I just
> wonder if something is wrong here.
> 
>> sessionInfo()
> R version 2.13.1 (2011-07-08)
> Platform: i386-pc-mingw32/i386 (32-bit)
> 
> locale:
> [1] LC_COLLATE=Thai_Thailand.874  LC_CTYPE=Thai_Thailand.874   
> LC_MONETARY=Thai_Thailand.874
> [4] LC_NUMERIC=C                  LC_TIME=Thai_Thailand.874
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> Thanks,
> Edward
> 
> 
> --------------------------------------------------------------------------------------------------------------
> NOTE: Prince of Songkla University will NEVER ask for your PSU Passport/Email Username or password by e-mail. 
> If you receive such a message, please report it to report-phish at psu.ac.th.
> --------------------------------------------------------------------------------------------
> @@@@ NEVER reply to any email asking for your PSU Passport/Email or other personal details. @@@@@ 
> --------------------------------------------------------------------------------------------
> 
> For more information, contact the PSU E-Mail Service by dialing 2121
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list