[R] round() seems inconsistent when rounding 5s

Spencer Graves spencer.graves at pdf.com
Sat Mar 15 23:35:40 CET 2003


Consider the following:
 > tst <- .5-1e-9
 > tst
[1] 0.5
 > round(tst)
[1] 0
 > tst1 <- .5+1e-9
 > tst1
[1] 0.5
 > round(tst1)
[1] 1

Does this answer the question?
Spencer Graves
####################################################
Rashid Nassar wrote:
> It may be my lack of unerstanding, but round() seems to me to give
> inconsistent results when rounding 5s as in the following examples?
> 
> 
>>round(1.45, 1)
> 
> [1] 1.4               # OK
> 
> 
>>round(2.45, 1)
> 
> [1] 2.5               # shouldn't this be 2.4?
> 
> 
>>round(1.05, 1)
> 
> [1] 1.1               #  1.0 ?
> 
> and signif():
> 
> 
>>signif(2.445, 3)
> 
> [1] 2.44             # OK
> 
> 
>>signif(3.445, 3)
> 
> [1] 3.45             # 3.44 ?
> 
> 
> 
>>version
> 
>          _
> platform i586-pc-linux-gnu
> arch     i586
> os       linux-gnu
> system   i586, linux-gnu
> status
> major    1
> minor    6.2
> year     2003
> month    01
> day      10
> language R
> 
> Many thanks!
> 
> Rashid Nassar
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list