File: rmultz2.R

package info (click to toggle)
r-cran-combinat 0.0-7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 124 kB
  • sloc: makefile: 1
file content (17 lines) | stat: -rw-r--r-- 423 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"rmultz2"<-
function(n, p, draws = length(n))
{
# 19 Feb 1997: From s-news 14 Feb 1997, Alan Zaslavsky
# 11 Mar 1997: Modified by Scott D. Chasalow
#
# Generate random samples from a multinomial(n, p) distn: varying n, 
# fixed p case.
#
	n <- rep(n, length = draws)
	lenp <- length(p)
	tab <- tabulate(sample(lenp, sum(n), TRUE, p) + lenp * rep(1:draws - 1, n),
		nbins = draws * lenp)
	dim(tab) <- c(lenp, draws)
	tab
}