Re: [R] rbinom for a matrix

From: Dylan Beaudette <dylan.beaudette_at_gmail.com>
Date: Wed, 09 Jul 2008 13:35:30 -0700

On Wednesday 09 July 2008, Ben Bolker wrote:
> Dylan Beaudette wrote:
> | On Wednesday 09 July 2008, Ben Bolker wrote:
> |> 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
> |
> | Wait a second. Are you trying to convert each probability into the most
> | likely '1' or '0' through rounding? The code example above will give
>
> you a
>
> | different answer every time you run it. Is that what you are looking for?
> |
> | Just curious,
> |
> | Dylan
>
> ~ I assumed that since the original poster said "convert each
> probability to a 1 or 0 using rbinom" that they did indeed want
> a random assignment, rather than rounding ...

Sorry about not including a reference to whom I was addressing. Meant that comment to go to the original poster.

-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

______________________________________________
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 Wed 09 Jul 2008 - 20:44:09 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 Wed 09 Jul 2008 - 21:32:08 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.

list of date sections of archive