From wolfg@ng@huber @ending from embl@de  Thu Sep 20 08:19:53 2018
From: wolfg@ng@huber @ending from embl@de (Wolfgang Huber)
Date: Thu, 20 Sep 2018 08:19:53 +0200
Subject: [Rd] A different error in sample()
In-Reply-To: <SYCPR01MB41112555F67E1CAD438FCB6BCD1C0@SYCPR01MB4111.ausprd01.prod.outlook.com>
References: <5b6950ce-ac7a-4f6a-da61-8e70d25bb08c@gmail.com>
 <CAO1zAVbHXAz9o7uf98Q5pUm7R8pSHFigAAtQn90FrGdPfqUn1A@mail.gmail.com>
 <SYCPR01MB41112555F67E1CAD438FCB6BCD1C0@SYCPR01MB4111.ausprd01.prod.outlook.com>
Message-ID: <90332569-2e20-e645-26de-9c2cd43eaea9@embl.de>

Besides wording of the documentation re truncating vs rounding, there 
is something peculiar going on with the fractional part of n:

 > table(sample.int(2.5, 1e6, replace = TRUE))

      1      2      3
399051 401035 199914

 > table(sample.int(3, 1e6, replace = TRUE))

      1      2      3
332956 332561 334483

 > table(sample.int(2.01, 1e6, replace = TRUE))

      1      2      3
497173 497866   4961

 > sessionInfo()
R Under development (unstable) (2018-09-17 r75319)
Platform: x86_64-apple-darwin17.7.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /Users/whuber/R/lib/libRblas.dylib
LAPACK: /Users/whuber/R/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] fortunes_1.5-4

loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0


20.9.18 03:00, Dario Strbenac scripsit:
> Good day,
> 
> The use of "rounding" also doesn't make sense. If The number is halfway between two integers, it is rounded to the nearest even integer.
> 
>> round(2.5)
> [1] 2
> 
> --------------------------------------
> Dario Strbenac
> University of Sydney
> Camperdown NSW 2050
> Australia

-- 
With thanks in advance-

Wolfgang

-------
Wolfgang Huber
Principal Investigator, EMBL Senior Scientist
European Molecular Biology Laboratory (EMBL)
Heidelberg, Germany

wolfgang.huber at embl.de
http://www.huber.embl.de

My book with Susan Holmes: http://www.huber.embl.de/msmb



[Rd] A different error in sample()
Wolfgang Huber