[R] repeat until function

Duncan Murdoch dmurdoch at pair.com
Wed Nov 12 19:27:27 CET 2003


On Wed, 12 Nov 2003 12:00:06 -0500, "Liaw, Andy" <andy_liaw at merck.com>
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 describing
>it.

That's a variation on the standard shuffling algorithm, which is
described in Knuth (but is not original to him). What you described
takes time n but uses storage N.  There's also a very similar
variation that takes time N and storage n; this is equivalent to the
McLeod and Bellhouse (1983) sampling algorithm.

Duncan murdoch




More information about the R-help mailing list