Re: [S] Question - Coding numeric vectors

Lutz Prechelt (
Wed, 25 Mar 1998 16:11:15 +0100

> I am attempting to simulate termite behavior with regard to selection of
> feeding sites. In setting up the simulation I need to generate what are
> essentially multinomial random numbers to represent which feeding site
> was chosen. Since I am unaware of a multinomial random number generator
> in S-plus (please enlighten me if I have missed something here)
> > probs <- c(.25, .35, .4, 0, 0) # Note the zero probabilities are required

Try this:

sites <- c(rep(1,25), rep(2,35), rep(3,40), rep(4,0), rep(5,0))

and then use


to pick a site at random with the required probabilities.


Lutz Prechelt | Whenever you
Institut f. Programmstrukturen und Datenorganisation | complicate things,
Universitaet Karlsruhe; D-76128 Karlsruhe; Germany | they get
(Phone: +49/721/608-4068, FAX: +49/721/608-7343) | less simple.
>>> Ever had negative research results? <<<

This message was distributed by To unsubscribe
send e-mail to with the BODY of the
message: unsubscribe s-news