From: <Bill.Venables_at_csiro.au>

Date: Wed, 12 Mar 2008 06:50:54 +1000

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 11 Mar 2008 - 20:56:53 GMT

Date: Wed, 12 Mar 2008 06:50:54 +1000

probMatrix <- matrix(runif(5*5), 5, 5) ## sets up the probs
binoMatrix <- rbinom(length(probMatrix), 1, probMatrix) ## simulates

dim(binoMatrix) <- dim(probMatrix) ## makes it a matrix also

What doesn't work?

## First I generate the matrix of probabilities for example purposes.

probMatrix <- matrix(NA,5,5){

for (i in 1:5)

probVectorI <- runif(5,0,1)

probMatrix[i,] <- probVectorI

}

# Now I want to take each element in probMatrix and use it as the

probability parameter in rbinom draw and generate a new matrix.
Something like this:

binomialMatrix <- rbinom(1,1,probMatrix)

# But that does not work. I know I can run a loop across each vector

of the matrix, but this seems like an bad way to do this.

---------------------------End Code--------------------------------

So any help would be appreciated.

Thanks,

EG

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 11 Mar 2008 - 20:56:53 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 11 Mar 2008 - 22:30:21 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*