[R] Fractional component of a number

edward.m at psu.ac.th edward.m at psu.ac.th
Sun Aug 28 05:59:51 CEST 2011


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



More information about the R-help mailing list