[R] Random numbers with PDF of user-defined function
Duncan Murdoch
murdoch.duncan at gmail.com
Thu Apr 29 13:22:31 CEST 2010
On 29/04/2010 5:40 AM, Nick Crosbie wrote:
> Hi,
>
> In S+/R, is there an easy way to generate random numbers with a
> probability distribution specified by an exact user-defined function?
>
> For example, I have a function:
>
> f(x) = 1/(365 * x), which should be fitted for values of x between 1 and
> 100,000
>
> How do I generate random numbers with a probability distribution that
> exactly maps the above function?
>
You can use sample() with the prob argument set to the values of f(x).
You probably want replace=TRUE as well.
Duncan Murdoch
> Nick
>
> This email and any attachments may contain information t...{{dropped:15}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list