[R] repeat until function
John Fox
jfox at mcmaster.ca
Wed Nov 12 15:47:39 CET 2003
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 +0000, Ragnhild Sørum wrote:
>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 (?) ((temp in tabel) ==FALSE)
> }
> else{ tabel[i] <- temp}
>
>I can't use repeat/until - don't exist....
>Any suggestions?
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
More information about the R-help
mailing list