Skip to content
Prev 161289 / 398500 Next

Vectorizing sample()

On 11/7/2008 12:00 PM, Stephen Collins wrote:
You might want to transform runif instead of using sample().  For 
example, if you want to generate M integers from 1:n_i, where n_i varies 
from sample to sample, you could use

gen <- ceiling(runif(M, 0, n))

(where n is a vector of length M giving the upper limits).

Duncan Murdoch