RE: [R] repeat until function

2003-11-12 Thread Liaw, Andy
> From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > > Ripley (1987) Stochastic Simulation, pp.80-1 for one. I am > pretty sure it is Knuth's book, although I don't have that to > hand. I attribute it to > Moses & Oakford (1963). Thanks to Brian, Peter and Duncan for the info. And I have

Re: [R] repeat until function

2003-11-12 Thread Duncan Murdoch
On Wed, 12 Nov 2003 12:00:06 -0500, "Liaw, Andy" <[EMAIL PROTECTED]> wrote : >This is obviously not efficient in high-level languages like R, but in terms >of algorithm, it is a lot more efficient than check-and-reject. IMHO this >should be described in some book, but I have not seen any book de

Re: [R] repeat until function

2003-11-12 Thread Peter Dalgaard
"Liaw, Andy" <[EMAIL PROTECTED]> writes: > This is obviously not efficient in high-level languages like R, but in terms > of algorithm, it is a lot more efficient than check-and-reject. IMHO this > should be described in some book, but I have not seen any book describing > it. I'm pretty sure I

RE: [R] repeat until function

2003-11-12 Thread Prof Brian Ripley
On Wed, 12 Nov 2003, Liaw, Andy wrote: > As others already pointed out, the fast way is to use sample(). > > What I'd like to add is the following, which I learned from peeking at the C > code underneath sample(): To draw n samples without replacement from 1:N > (N>=n), you only need a loop from

RE: [R] repeat until function

2003-11-12 Thread Liaw, Andy
scribing it. Just my $0.02... Andy > -Original Message- > From: Ragnhild Sørum [mailto:[EMAIL PROTECTED] > Sent: Wednesday, November 12, 2003 9:26 AM > To: [EMAIL PROTECTED] > Subject: [R] repeat until function > > > Hi, > > I'm in this situation: > I w

Re: [R] repeat until function

2003-11-12 Thread Philipp Pagel
> I what to generate N random numbers(integer) that are different from each > other. > One suggestion: > > tabel <- rep(NULL, N) > for (i in 1:N){ > temp <- as.integer(runif(1,1,max)) > if(temp in tabel) { > repeat (?) (temp <- as.integer(runif(i,i,max))) > until (?) ((temp in tab

Re: [R] repeat until function

2003-11-12 Thread John Fox
Dear Ragnhild, You can break out of a loop (see ?break), but, if I understand correctly what you want, why not just use sample(max, N)? John At 02:26 PM 11/12/2003 +, Ragnhild Sørum wrote: Hi, I'm in this situation: I what to generate N random numbers(integer) that are different from each

RE: [R] repeat until function

2003-11-12 Thread RBaskin
2003 9:26 AM To: [EMAIL PROTECTED] Subject: [R] repeat until function Hi, I'm in this situation: I what to generate N random numbers(integer) that are different from each other. One suggestion: tabel <- rep(NULL, N) for (i in 1:N){ temp <- as.integer(runif(1,1,max)) if(temp in ta

[R] repeat until function

2003-11-12 Thread Ragnhild Sørum
Hi, I'm in this situation: I what to generate N random numbers(integer) that are different from each other. One suggestion: tabel <- rep(NULL, N) for (i in 1:N){ temp <- as.integer(runif(1,1,max)) if(temp in tabel) { repeat (?) (temp <- as.integer(runif(i,i,max))) until (?) ((tem