[R] Sampling with conditions
SarahJoyes
sjoyes at uoguelph.ca
Mon Nov 7 23:22:54 CET 2011
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.
More information about the R-help
mailing list