From radford at cs.toronto.edu  Thu Jun 18 20:45:01 2015
From: radford at cs.toronto.edu (Radford Neal)
Date: Thu, 18 Jun 2015 14:45:01 -0400
Subject: [Rd] Add-on argument in sample()
In-Reply-To: <mailman.19.1434621604.11302.r-devel@r-project.org>
References: <mailman.19.1434621604.11302.r-devel@r-project.org>
Message-ID: <20150618184501.GB4656@cs.toronto.edu>

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



[Rd] Add-on argument in sample()
Radford Neal