://sites.google.com/a/aims.ac.za/fredo/
On Tue, Jul 19, 2016 at 9:11 PM, wrote:
N <- 100
C <- 50
x <- numeric(N)
for (i in 1:N){
x[i] <- sample(C-sum(x),1)
}
x
sum(x)
*Frederic Ntirenganya >*
Sent by: "R-help"
07/19/2016 01:41 PM
To
"r-help@r-project.org&qu
r (i in 1:N){
> x[i] <- sample(C-sum(x),1)
> }
> x
> sum(x)
>
>
>
>
> *Frederic Ntirenganya >*
> Sent by: "R-help"
>
> 07/19/2016 01:41 PM
> To
> "r-help@r-project.org" ,
>
> cc
> Subject
> [R] Sampe numbers
>
>
N <- 100
C <- 50
x <- numeric(N)
for (i in 1:N){
x[i] <- sample(C-sum(x),1)
}
x
sum(x)
Frederic Ntirenganya
Sent by: "R-help"
07/19/2016 01:41 PM
To
"r-help@r-project.org" ,
cc
Subject
[R] Sampe numbers
Hi Guys,
I am trying to sample 100 number
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 v
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.
Mobile:(+254)71
5 matches
Mail list logo