[R] Sampe numbers

Frederic Ntirenganya
2016-07-19T18:54:57Z

The problem is that there
are some zeros  while the numbers should range from 1 to  100

As the replace= TRUE if the smallest candidate is 1 may be replaced
because if I can have 1, fifty times this is equal to 50.
Remember that it is a sampling with a replacement

I am still wondering how I can remove the zero value.


Frederic Ntirenganya
Maseno University,
African Maths Initiative,
Kenya.
Mobile:(+254)718492836
Email: fredo at aims.ac.za
https://sites.google.com/a/aims.ac.za/fredo/

On Tue, Jul 19, 2016 at 9:11 PM, <JLucke at ria.buffalo.edu> 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 <ntfredo at gmail.com <ntfredo at
gmail.com>>*
> Sent by: "R-help" <r-help-bounces at r-project.org>
>
> 07/19/2016 01:41 PM
> To
> "r-help at r-project.org" <r-help at 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 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)718492836
> Email: fredo at aims.ac.za
> https://sites.google.com/a/aims.ac.za/fredo/
>
>
>                 [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>