rbin {lazy.stat}R Documentation

Binomial Random Numbers

Description

Binomial Random Numbers

Usage

rbin(size, prob, colvec = 0)

Arguments

size

n x p vector/matrix of # of trials
When the size of size is different from the one of prob, it will be recycled.

prob

n x p vector/matrix of probabilities

colvec

= 1 to make the result a column vector

Details

This is basically equivalent to
res <- mapply( function(size,prob) rbinom(1,size,prob) , size, prob )
dim(res)=dim(prob)

Value

A vector/matrix of the same size as prob whose ij element is from rbinom( 1, size[i,j], prob[i,j] )

Examples

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) )


[Package lazy.stat version 0.1.4 Index]