[Rd] Add-on argument in sample()

Radford Neal radford at cs.toronto.edu
Thu Jun 18 20:45:01 CEST 2015

William Dunlap writes:

> I don't like the idea of having a length-1 dim attribute trigger some
> behavior of sample.  (Should a length-2 dim cause it to sample
> rows of a matrix, as unique() and duplicated() do?).

I wasn't too clear.  I would want any dim attribute on its first
argument to cause sample to treat it as the vector of values to sample
from, rather than as the upper limit for the set of integers to sample
from.  This is consistent with how higher-dimensional arrays can be
treated as vectors in some other contexts.  But I'd expect the 1D case
to be the common case.

The basic problem, here and in other places, is that R (and S) don't
distinguish a scalar from a vector of length one.  I think this was a
mistake, which one can try to unwind now by at least not treating a
vector of length one as a scalar if it is explicitly marked as a
vector by a dim attribute.

Allowing a dim attribute of length zero (presently disallowed) might
also be a good idea, because it could be used to explicitly mark a
single number as a scalar, not a vector of length one.

   Radford Neal

More information about the R-devel mailing list