Re: [R] choosing a random element from a vector

2008-04-28 Thread Henrique Dallazuanna
Try this: x <- sample(0:1, rep = TRUE, 1e6, prob=c(0.4, 0.6)) sample(which(x == 1), 1) On Mon, Apr 28, 2008 at 1:12 PM, <[EMAIL PROTECTED]> wrote: > > I have a vector consisting of zeroes and ones, e.g. 101001. > > I would like to pick a random element from this vector equal to one. In > the > e

[R] choosing a random element from a vector

2008-04-28 Thread osmirnov
I have a vector consisting of zeroes and ones, e.g. 101001. I would like to pick a random element from this vector equal to one. In the example above, that means that only elements 1, 3, or 6 can be chosen. Is there a simple and fast way to do that? (my vector of zeroes and ones is very large)