[R] Generate N random numbers with a given probability and condition

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Thu Jul 5 00:56:59 CEST 2018

This looks like homework (which is off topic here per the Posting Guide). Also, please send your emails in plain text format to avoid us seeing your message differently than you do.

On July 4, 2018 3:21:34 PM PDT, Nelly Reduan <nell.redu using hotmail.fr> wrote:
>Dear all,
>I would like to generate N random numbers with a given probability and
>condition but I'm not sure how to do this.
>For example, I have N = 20 and the vector from which to choose is
>seq(0, 10, 1). I have tested:
>x <- sample(seq(0, 10, 1), 20, replace=TRUE, prob=rep(0.28,
>times=length(seq(0, 10, 1))))
>But I don�t know how to put the condition sum(x) <= max(seq(0, 10, 1)).
>Many thanks for your time
>	[[alternative HTML version deleted]]

Sent from my phone. Please excuse my brevity.

More information about the R-help mailing list