[R] random generation of a factor
Christian Bieli
christian.bieli at gmx.ch
Mon May 22 22:22:34 CEST 2006
Dear Dave and Roland
Thanks for your answers! I think sample() does the job I'm looking for.
I also came up with rmultinom(), but could not make it working, because
I don't want several multinomial distributed vectors, but one vector
with K levels of predefined proportions. Propably there is a way to do
that with rmultinom() - Dave, could you make up a short example?
Best wishes
Christian
Rau, Roland schrieb:
>Hi,
>
>
>
>
>>Does anybody know a function that generates a factor of
>>length N with K
>>levels given the proportions c(p1, p2,... ,pk)? It would not
>>
>>
>
>## does this code piece help you?
>
>mydata <- c("yesterday", "today", "tomorrow")
>myproportions <- c(0.3, 0.5, 0.2)
>
>n <- 20
>sample(x=mydata, size=n, replace=TRUE, prob=myproportions)
>
>cat("Best,\nRoland\n")
>
>----------
>This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance.
>
>
>
>
More information about the R-help
mailing list