Re: [R] sample function

From: Marc Schwartz <MSchwartz_at_medanalytics.com>
Date: Fri 11 Mar 2005 - 14:20:15 EST

On Thu, 2005-03-10 at 20:54 -0600, mirage sell wrote:
> Hi everyone, I need help.
> I want to have a "uniform" kind distribution. When I used sample function I
> got almost twice many zeros compared to other numbers. What's wrong with my
> command ?
>
> temp <-sample(0:12, 2000, replace=T,prob=(rep(1/13,13)))
> hist(temp)
>
> Thanks in advance,

Hint: take note that there are only 12 cells in the plot, not 13...

However, note that the frequency of the 13 elements are appropriate:

> table(sample(0:12, 2000, replace=T))

  0 1 2 3 4 5 6 7 8 9 10 11 12 158 156 151 163 156 158 146 154 134 158 146 147 173

Review the details of how the breaks are selected in ?hist.

BTW, you do not need to specify the 'prob' argument if you want equal probabilities as per my example above.

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Mar 14 10:32:49 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:46 EST