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.com>wrote: > 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: > http://r.789695.n4.nabble.com/generate-randomly-a-value-of-a-vector-tp3798190p3798190.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. > [[alternative HTML version deleted]] ______________________________________________ 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.