[Rd] sample suggestion

From: Göran Broström <gb_at_stat.umu.se>
Date: Thu 07 Oct 2004 - 17:00:01 EST


I have been bitten by what is clearly described on the help page for
'sample', namely sampling from a population of size one. I agree that it is
convenient to have an exception if 'length(x) == 1', but my suggestion is to enforce the exception only if 'x' is numeric. In any case, if x is not numeric and of length 1, all you get is an error message.

I would like 'sample("tre", 1)' to return "tre", and 'sample(3, 1)' to return a natural number less than 4. It seems easy to achieve that by changing the line

if (length(x) == 1 && x >= 1) {

to

if (length(x) == 1 && is.numeric(x) && x >= 1) {

in 'sample'.

Isn't that a good idea? An alternative suggestion would be to implement
'resample' (from the examples) in 'base'.

Göran

PS. Congratulations to the Core Team for reaching an excellent 2.0.0!

-- 
 Göran Broström                    tel: +46 90 786 5223
 Department of Statistics          fax: +46 90 786 6614
 Umeå University                   http://www.stat.umu.se/egna/gb/
 SE-90187 Umeå, Sweden             e-mail: gb@stat.umu.se

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu Oct 07 17:20:46 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:00:28 EST