Not sure this is valid that you can have 9 random samples out of 10, but the last one has to be fixed to meet the restraint, sum=10.
Weidong On Mon, Nov 7, 2011 at 5:22 PM, SarahJoyes <sjo...@uoguelph.ca> wrote: > Hey everyone, > I am at best, an amateur user of R, but I am stuck on how to set-up the > following situation. > I am trying to select a random sample of numbers from 0 to 10 and insert > them into the first column of a matrix (which will used later in a loop). > However, I need to have those numbers add up to 10. How can I set those > conditions? > So far I have: > n<-matrix(0,nr=5,ncol=10) > for(i in 1:10){n[i,1]<-sample(0:10,1)} > How do I set-up the "BUT sum(n[i,1])=10"? > Thanks > SarahJ > > -- > View this message in context: > http://r.789695.n4.nabble.com/Sampling-with-conditions-tp4014036p4014036.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. > ______________________________________________ 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.