Re: [Rd] [patch] add is.set parameter to sample()

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Thu, 25 Mar 2010 11:53:26 +0100

>>>>> "AndrewC" == Andrew Clausen <clausen_at_econ.upenn.edu> >>>>> on Tue, 23 Mar 2010 08:04:12 -0400 writes:

    AndrewC> Hi all,
    AndrewC> I forgot to test my patch! I fixed a few bugs.

and this time, you even forgot to attach it (in a way to pass through the list filters).

Note however, that all this seems unnecessary, as we have sample.int()
and a trivial definition of resample()
at least in R-devel, which will be released as R 2.11.0 on April 22.

Thank you anyway, for your efforts!
Martin

Martin Maechler, ETH Zurich

    AndrewC> On 22 March 2010 22:53, Andrew Clausen <clausen_at_econ.upenn.edu> wrote:
>> Hi all,
>>
>> sample() has some well-documented undesirable behaviour.
>>
>> sample(1:6, 1)
>> sample(2:6, 1)
>> ...
>> sample(5:6, 1)
>>
>> do what you expect, but
>>
>> sample(6:6, 1)
>> sample(1:6, 1)
>>
>> do the same thing.
>>
>> This behaviour is documented:
>>
>>     If 'x' has length 1, is numeric (in the sense of 'is.numeric') and
>>     'x >= 1', sampling _via_ 'sample' takes place from '1:x'.  _Note_
>>     that this convenience feature may lead to undesired behaviour when
>>     'x' is of varying length 'sample(x)'.  See the 'resample()'
>>     example below.
>>
>> My proposal is to add an extra parameter is.set to sample() to control
>> this behaviour.  If the parameter is unspecified, then we keep the old
>> behaviour for compatibility.  If it is TRUE, then we treat the first
>> parameter x as a set.  If it is FALSE, then we treat it as a set size.
>>  This means that
>>
>> sample(6:6, 1, is.set=TRUE)
>>
>> would return 6 with probability 1.
>>
>> I have attached a patch to implement this new option.
>>
>> Cheers,
>> Andrew
>>

    AndrewC> ______________________________________________
    AndrewC> R-devel_at_r-project.org mailing list     AndrewC> https://stat.ethz.ch/mailman/listinfo/r-devel

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 25 Mar 2010 - 11:02:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 25 Mar 2010 - 19:32:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive