rbin {lazy.stat} | R Documentation |
Binomial Random Numbers
rbin(size, prob, colvec = 0)
size |
n x p vector/matrix of # of trials |
prob |
n x p vector/matrix of probabilities |
colvec |
= 1 to make the result a column vector |
This is basically equivalent to
res <- mapply( function(size,prob) rbinom(1,size,prob) , size, prob )
dim(res)=dim(prob)
A vector/matrix of the same size as prob whose ij element is from rbinom( 1, size[i,j], prob[i,j] )
set.seed(1701) x <- rbin( c(1000,500), c(0.25, 0.5) ) Print( mean(x), var(x), sqrt(var(x)) ) prob <- matrix( c( .2, .3, .9, .4, .8, .1 ), 2,3, byrow=1 ) Print( prob, rbin(c(1000,100000),prob) )