From kjetil at entelnet.bo  Wed Mar  5 21:20:01 2003
From: kjetil at entelnet.bo (kjetil brinchmann halvorsen)
Date: Thu Mar  6 02:20:33 2003
Subject: [Rd] sample (PR#2546)
In-Reply-To: <3E5BBE7A.3090705@pburns.seanet.com>
Message-ID: <3E666A01.21234.1599B28@localhost>

On 25 Feb 2003 at 19:05, Patrick Burns wrote:

> There is rumour that some of my mail didn't go where it should have because
> I don't know how to work email.  It was suggested that I summarize here.
> 
> The issue is with sample when the first argument is length 1.  Current
> behaviour is:
> 

I thought about this. It would be nice to have the behaviour Patrick 
Burns proposes, but there is a problem: What to do when the 
length one argument is numeric? Look at the following:

> sample(1)
[1] 1
> sample(7)
[1] 4 6 1 5 2 3 7
> sample(6.9)
[1] 2 4 5 1 3 6   # 6.9 truncated to 6
> sample(0)     
[1] 0                #  What one should expect here is not easy to 
                      #  know, as the help page requires a positive
                      #  integer
> sample(-3)
[1] -3              # same
> sample(0.5)
[1] 0.5
> sample(1.5)
[1] 1               # truncated

So what to do with length one numerical arguments, truncate, as seems 
to be done (but not always):

> sample(0.99)
[1] 0.99

or round, or give an error if not a positive integer, or? 
However it is done it will surely break some code. 

Kjetil Halvorsen


>  > sample('a', 1)
> Error in sample(x, size, replace, prob) : invalid first argument
>  > sample(3+0i, 1)
> Error in x >= 1 : illegal comparison with complex values
>  > sample(TRUE, 1)
> [1] 1
>  > sample(FALSE, 1)
> [1] FALSE
>  > sample(NA, 1)
> Error in if (length(x) == 1 && x >= 1) { :
>         missing value where logical needed
>  > sample(.5, 1)
> [1] 0.5
> 
> 
> The proposed behaviour is:
> 
>  > sample('a', 1)
> [1] "a"
>  > sample(3+0i, 1)
> [1] 3+0i
>  > sample(TRUE, 1)
> [1] TRUE
>  > sample(FALSE, 1)
> [1] FALSE
>  > sample(NA, 1)
> [1] NA
>  > sample(.5, 1)
> [1] 0.5
> 
> 
> For some reason that I haven't yet grasped, the current
> behaviour seems to be preferred to the proposed behaviour.
> 
> Pat Burns
> 
> patrick@burns-stat.com
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-devel


[Rd] sample (PR#2546)
kjetil brinchmann halvorsen