Re: [Rd] A different error in sample()

2018-09-20 Thread Martin Maechler
> Martin Maechler > on Thu, 20 Sep 2018 09:20:46 +0200 writes: > Wolfgang Huber > on Thu, 20 Sep 2018 08:47:47 +0200 writes: >> FWIW, I suspect this is related to the function >> R_unif_index that was introduced in src/main/RNG.c around >> revision 72356, or

Re: [Rd] A different error in sample()

2018-09-20 Thread peter dalgaard
Yup, that is a bug, at least in the documentation. Probably a clearer example is x <- seq(2.001, 2.999, length.out=999) threes <- sapply(x, function(y) table(sample(y, 1, replace=TRUE))[3]) plot(threes, type="l") curve(1*(x-2)/x, add=TRUE, col="red") which is entirely consistent with

Re: [Rd] A different error in sample()

2018-09-20 Thread Joris Meys
To be more clear: I do NOT state that the function "round" is used. I read the documentation as "non integer positive numerical values will be replaced by the next smallest integer", the important part being the NEXT smallest integer, i.e. how ceiling() does it. So that's exactly what I would

Re: [Rd] A different error in sample()

2018-09-20 Thread Emil Bode
But do we handle it as an error in what sample does, or how the documentation is? I think what is done now would be best described as "ceilinged", i.e. what ceiling() does. But is there an English word to describe this? Or just use "converted to the next smallest integer"? But then again, what

Re: [Rd] A different error in sample()

2018-09-20 Thread lmo via R-devel
Although it seems to be pretty weird to enter a numeric vector of length one that is not an integer as the first argument to sample(), the results do not seem to match what is documented in the manual. In addition, the results below do not support the use of round rather than truncate in the

Re: [Rd] A different error in sample()

2018-09-20 Thread Kim Seonghyun
] A different error in sample() 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 Camper

Re: [Rd] A different error in sample()

2018-09-20 Thread Martin Maechler
> Wolfgang Huber > on Thu, 20 Sep 2018 08:47:47 +0200 writes: > FWIW, I suspect this is related to the function > R_unif_index that was introduced in src/main/RNG.c around > revision 72356, or the way this function is used in > do_sample in src/main/random.c. Yes, it

Re: [Rd] A different error in sample()

2018-09-20 Thread Wolfgang Huber
FWIW, I suspect this is related to the function R_unif_index that was introduced in src/main/RNG.c around revision 72356, or the way this function is used in do_sample in src/main/random.c. 20.9.18 08:19, Wolfgang Huber scripsit: Besides wording of the documentation re truncating vs rounding,

Re: [Rd] A different error in sample()

2018-09-20 Thread Wolfgang Huber
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

Re: [Rd] A different error in sample()

2018-09-19 Thread Dario Strbenac
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

Re: [Rd] A different error in sample()

2018-09-19 Thread Joris Meys
I believe the word "truncated" is causing the confusion. 3 is "the next smallest integer" following 2.5. But it is not the truncation done by trunc(). Rewording to "rounding the next smallest integer" would get rid of that confusion imho. Cheers Joris On Wed, Sep 19, 2018 at 7:57 PM Duncan

[Rd] A different error in sample()

2018-09-19 Thread Duncan Murdoch
This may be a doc error or a coding bug. The help page for sample says: "Non-integer positive numerical values of n or x will be truncated to the next smallest integer, which has to be no larger than .Machine$integer.max." This is not true: > table(sample(2.5, 100, replace = TRUE))