Re: [R] Sampe numbers

2016-07-19 Thread Daniel Nordlund
by: "R-help" <r-help-boun...@r-project.org> 07/19/2016 01:41 PM To "r-help@r-project.org" <r-help@r-project.org>, cc Subject [R] Sampe numbers Hi Guys, I am trying to sample 100 numbers from 1:100 i did it like this: sample(1:100,100, replace= TRUE) but i want

Re: [R] Sampe numbers

2016-07-19 Thread Frederic Ntirenganya
0 > x <- numeric(N) > for (i in 1:N){ > x[i] <- sample(C-sum(x),1) > } > x > sum(x) > > > > > *Frederic Ntirenganya <ntfr...@gmail.com <ntfr...@gmail.com>>* > Sent by: "R-help" <r-help-boun...@r-project.org> > > 07/19/2016 01:41

Re: [R] Sampe numbers

2016-07-19 Thread JLucke
N <- 100 C <- 50 x <- numeric(N) for (i in 1:N){ x[i] <- sample(C-sum(x),1) } x sum(x) Frederic Ntirenganya <ntfr...@gmail.com> Sent by: "R-help" <r-help-boun...@r-project.org> 07/19/2016 01:41 PM To "r-help@r-project.org" <r-help@r-projec

Re: [R] Sampe numbers

2016-07-19 Thread Greg Snow
I think that you need to reconsider your conditions. The smallest number in your candidate set is 1, so if you sample 100 1's they will add to 100 which is greater than 50. So to have a set of numbers that sums to 50 you will need to either include negative numbers, 0's, or sample fewer than 50

[R] Sampe numbers

2016-07-19 Thread Frederic Ntirenganya
Hi Guys, I am trying to sample 100 numbers from 1:100 i did it like this: sample(1:100,100, replace= TRUE) but i want again include a constraint that their sum must be equal to 50 How could I do it? Cheers Frederic Ntirenganya Maseno University, African Maths Initiative, Kenya.