From ligges at statistik.uni-dortmund.de  Sat Oct 29 18:20:28 2005
From: ligges at statistik.uni-dortmund.de (ligges@statistik.uni-dortmund.de)
Date: Sat, 29 Oct 2005 18:20:28 +0200 (CEST)
Subject: [Rd] quirk in "sample" (PR#8264)
Message-ID: <20051029162028.5747E21EB9@slim.kubism.ku.dk>

ihd at isds.duke.edu wrote:

> Hi,
> There is a property of "sample" that I believe is undesirable,
> at least for me.
> sample(1:3,1) 
> chooses from the set {1,2,3}
> but 
> sample(3:3,1) 
> chooses also from {1,2,3} even though
> it would be used to sample from an interval [a,b] in general.
> So  a program that generates an interval [a,b] for sampling will behave
> differently when the endpoints are the same than when
> the endpoints are different.

No, this is not a bug:

 > (x1 <- 3:3)
[1] 3
 > (x2 <- c(3,3))
[1] 3 3

3:3 are not two points, but one point!

sample(x2, 1) always gives "3", but sample(x1, 1) gives a number between 
1 and 3, as documented: "If x has length 1, sampling takes place from 1:x."
See the Exmaple section how to circumvent the (for you!) undesired 
behaviour.

Uwe Ligges






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



[Rd] quirk in "sample" (PR#8264)
ligges@statistik.uni-dortmund.de