[R] generate randomly a value of a vector

2011-09-08 Thread Boris Beranger
Hi everyone, I have a zero vector of length N and I would like to randomly allocate the value 1 to one of the values of this vector. I presume I have to use the uniform distribution but could someone tell me how I should process? Thanks in advance, Boris -- View this message in context:

Re: [R] generate randomly a value of a vector

2011-09-08 Thread andrija djurovic
Hi Boris. Here is one approach: N-100 a-rep(0,N) a[sample(N,1)]-1 a which(a==1) Look ?sample, ?which. Andrija On Thu, Sep 8, 2011 at 10:42 AM, Boris Beranger borisberan...@gmail.comwrote: Hi everyone, I have a zero vector of length N and I would like to randomly allocate the value 1 to

Re: [R] generate randomly a value of a vector

2011-09-08 Thread Patrick Breheny
On 09/08/2011 04:42 AM, Boris Beranger wrote: I have a zero vector of length N and I would like to randomly allocate the value 1 to one of the values of this vector. I presume I have to use the uniform distribution but could someone tell me how I should process? rmultinom(m,1,rep(1,N)) where

Re: [R] generate randomly a value of a vector

2011-09-08 Thread Boris Beranger
Thank you very much Andrija, I have been do some research and was about to post the same solution. Boris -- View this message in context: http://r.789695.n4.nabble.com/generate-randomly-a-value-of-a-vector-tp3798190p3798595.html Sent from the R help mailing list archive at Nabble.com.