Re: [R] rbinom for a matrix

From: Ben Bolker <>
Date: Wed, 09 Jul 2008 19:13:52 +0000 (UTC)

ACroske <Audy3272 <at>> writes:

> I have a large matrix full of probabilities; I would like to convert each
> probability to a 1 or a 0 using rbinom.
> How can I do this on the entire matrix? The matrix was converted from a
> raster ArcMap dataset, so the matrix is essentially a map. Because of this,
> I have no column headings.
> Thanks!

  How about


  or (perhaps marginally more efficiently?)

y <- (runif(m)<m)
storage.mode(y) <- "double"

  Ben Bolker mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Jul 2008 - 19:18:37 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 Thu 10 Jul 2008 - 01:31:43 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive