ACroske <Audy3272 <at> yahoo.com> 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

matrix(rbinom(length(m),prob=m,size=1),nrow=nrow(m))

  or (perhaps marginally more efficiently?)

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

  Ben Bolker

______________________________________________
R-help@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.

Reply via email to